Skip to content

Instantly share code, notes, and snippets.

@mjmeilahn
Last active May 3, 2023 23:32
Show Gist options
  • Save mjmeilahn/52c59d4233e9507d7548e4f15b525637 to your computer and use it in GitHub Desktop.
Save mjmeilahn/52c59d4233e9507d7548e4f15b525637 to your computer and use it in GitHub Desktop.
Python: Performance Log Sequences
"""
Return an array of User IDs that have logged the correct actions
taken at least once in the performance logs with this sequence:
A -> B -> C
"""
logs = [
{ 'userID': 1, 'action': 'C' },
{ 'userID': 2, 'action': 'B' },
{ 'userID': 3, 'action': 'B' },
{ 'userID': 2, 'action': 'A' },
{ 'userID': 2, 'action': 'B' },
{ 'userID': 3, 'action': 'C' },
{ 'userID': 3, 'action': 'A' },
{ 'userID': 1, 'action': 'A' },
{ 'userID': 3, 'action': 'B' },
{ 'userID': 2, 'action': 'C' },
{ 'userID': 1, 'action': 'B' },
{ 'userID': 3, 'action': 'C' },
]
def performanceLogs(lis):
users = []
for i in lis:
ID = i['userID']
user = [k for k in lis if ID == k['userID']]
actions = ''.join(list(map(lambda k: k['action'], user)))
if ('ABC' in actions) and ID not in users:
users.append(ID)
return users
print(performanceLogs(logs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment