Last active
May 3, 2023 23:32
-
-
Save mjmeilahn/52c59d4233e9507d7548e4f15b525637 to your computer and use it in GitHub Desktop.
Python: Performance Log Sequences
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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