Question

In: Computer Science

Given a collection of actions and userIds an error occurs when a userId takes a specific...

Given a collection of actions and userIds an error occurs when a userId takes a specific action in order for example. Preferably in Javascript. Python or Java is okay too.

A => B => => C gives an errror
B => A => C no error and etc

Write a function that takes in a list of (Actions, UserIds) pairs and returns the user Id that ecounters the error

Sample Input:

action_user_1 = [
["A", "1"],
["B", "1"],
["B", "2"],
["C", "1"],
["C", "2"],
["C", "3"],
["A", "2],
["A", "3"],
["A", "2"],
["B", "2],
["C", "2"],
]

Expected output 1,2

action_user_2 = [
["A", "1"],
["A", "1"]
["A", "1"]
["B", "1"],
["B", "2"],
["C", "2"],
["C", "2"],
["C", "3"],
["A", "2],
["A", "3"],
["A", "2"],
["B", "2],
["C", "2"],
]

Expected output 2

Solutions

Expert Solution

def ErrorUsers(action_user):
  '''
  Returns the error userids
  '''
  uniq_user = set() #unique userids
  error = []
  for lst in action_user: #for each userid
    uniq_user.add(lst[1]) #add into a set to get unique values
  for user in uniq_user: #for each user
    u=[]
    for lst in action_user: #for each action list
      if user == lst[1]: #if user == action user
        u.append(lst[0]) #append the action
    new=''.join(u) #make a string by joining the characters within a action list u
    if 'ABC' in new: #if ABC in order present then error user append
      error.append(user)
    elif 'BC' in new: #if BC in order present then error user append
       error.append(user)
  return error #return the error user list


if __name__ == "__main__":
  action_user_1 = [
  ["A", "1"],
  ["B", "1"],
  ["B", "2"],
  ["C", "1"],
  ["C", "2"],
  ["C", "3"],
  ["A", "2"],
  ["A", "3"],
  ["A", "2"],
  ["B", "2"],
  ["C", "2"],
  ]
  print(action_user_1)
  print("Error users: ",','.join(ErrorUsers(action_user_1)))
  action_user_2 = [
  ["A", "1"],
  ["A", "1"],
  ["A", "1"],
  ["B", "1"],
  ["B", "2"],
  ["C", "2"],
  ["C", "2"],
  ["C", "3"],
  ["A", "2"],
  ["A", "3"],
  ["A", "2"],
  ["B", "2"],
  ["C", "2"],
  ]
  print(action_user_2)
  print("Error users: ",','.join(ErrorUsers(action_user_2)))

Output:

Though I write comment with each line if you have any doubt you can ask in the comment. Thanks.


Related Solutions

a) Describe the specific reaction that occurs in each of the tests when they are positive...
a) Describe the specific reaction that occurs in each of the tests when they are positive by describing what happens chemically to give a blue-green solution in the Chromic Acid test (positive test), what happens to give a silver precipitate in the Tollen�s test (positive test) and what happens to give a precipitate in the Iodoform test (positive test). b)describe how you could use any single instrumental method to distinguish all of the unknown above. you mayuse MS, IR, H-NMR...
QUESTION 1 A Type II error occurs when we ________. reject the null hypothesis when it...
QUESTION 1 A Type II error occurs when we ________. reject the null hypothesis when it is actually true reject the null hypothesis when it is actually false do not reject the null hypothesis when it is actually false do not reject the null hypothesis when it is actually true QUESTION 2 A lower level of significance makes it harder to reject the null hypothesis. True False QUESTION 3 A professional sports organization is going to implement a test for...
What is the error message that occurs when the manager sends Set_Request to a read-only object?...
What is the error message that occurs when the manager sends Set_Request to a read-only object? Also, list out any three error messages in SNMP v1.
What is the critical error being committed when an employee who reports to you takes a...
What is the critical error being committed when an employee who reports to you takes a complaint directly to your manager and receives resolution?
[25] Price fixing occurs when competitors in a market agree on: A) specific prices to be...
[25] Price fixing occurs when competitors in a market agree on: A) specific prices to be charged for their products. B) the price below which they will not sell their products. C) who will submit the lowest offer when pricing is done with sealed bids. D) any of the above. [26] Which of the following would be a per se violation of the Sherman Act? A) Price discrimination. B) Trade association activities. C) Unfair methods of competition. D) Territorial division...
1. A Type I error occurs when we: A. reject a true null hypothesis B. reject...
1. A Type I error occurs when we: A. reject a true null hypothesis B. reject a false null hypothesis C. do not reject a false null hypothesis D. do not reject a true null hypothesis 2. Whenever the null hypothesis is not rejected, the alternative hypothesis: A. is true B. must be modified C. is rejected D. is not rejected
3. For the following collection of statements, describe the sets of actions, objects, and subjects; and...
3. For the following collection of statements, describe the sets of actions, objects, and subjects; and draw an access control matrix to represent the scenario. 1 Mark Alice can climb trees and eat apples. Bob can climb fences, eat apples, and wave flags. Trees can hurt apples. Carol can jump waves and wave flags.
: Keeping in view, the possible raters’ error in performance appraisal, discuss the specific error that...
: Keeping in view, the possible raters’ error in performance appraisal, discuss the specific error that occurred in this scenario and how it could be handled? Justify your answer with solid arguments.
Identify the actions of the seven specific types of neoplasm behaviors
Identify the actions of the seven specific types of neoplasm behaviors
Keeping in view, the possible raters’ error in performance appraisal, discuss the specific error that occurred...
Keeping in view, the possible raters’ error in performance appraisal, discuss the specific error that occurred in this scenario and how it could be handled? Justify your answer with solid arguments.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT