Advertisement
mbratanov

03. Naughty or Nice

Oct 12th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. def output(nice_list, naughty_list, not_found_list):
  2.     result = []
  3.     if nice_list:
  4.         result.append(f"Nice: {', '.join(nice_list)}")
  5.     if naughty_list:
  6.         result.append(f"Naughty: {', '.join(naughty_list)}")
  7.     if not_found_list:
  8.         result.append(f"Not found: {', '.join(not_found_list)}")
  9.  
  10.     return "\n".join(result)
  11.  
  12.  
  13. def naughty_or_nice_list(kids_list, *commands, **keywords):
  14.     nice_list = []
  15.     naughty_list = []
  16.  
  17.     for command in commands:
  18.         number, behavior = command.split('-')
  19.         number = int(number)
  20.  
  21.         matching_kids = [kid for kid in kids_list if kid[0] == number]
  22.  
  23.         if len(matching_kids) == 1:
  24.             kid = matching_kids[0]
  25.             if behavior == "Nice":
  26.                 nice_list.append(kid[1])
  27.             elif behavior == "Naughty":
  28.                 naughty_list.append(kid[1])
  29.             kids_list.remove(kid)
  30.  
  31.     for name, behavior in keywords.items():
  32.         matching_kids = [kid for kid in kids_list if kid[1] == name]
  33.  
  34.         if len(matching_kids) == 1:
  35.             kid = matching_kids[0]
  36.             if behavior == "Nice":
  37.                 nice_list.append(kid[1])
  38.             elif behavior == "Naughty":
  39.                 naughty_list.append(kid[1])
  40.             kids_list.remove(kid)
  41.  
  42.     not_found_list = [kid[1] for kid in kids_list]
  43.     result = output(nice_list, naughty_list, not_found_list)
  44.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement