Advertisement
GalinaKG

Untitled

Oct 20th, 2022 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. def put_kid_in_the_santa_list(santa_list, modified_list, arg, type_kid):
  2.     for code, nam in modified_list.items():
  3.         if code == arg:
  4.             if len(nam) == 1:
  5.                 modified_list[code] = []
  6.                 santa_list[type_kid].extend(nam)
  7.     return santa_list, modified_list
  8.  
  9.  
  10. def naughty_or_nice_list(full_list, *command, **commands):
  11.     modified_list = {}
  12.     names = {}
  13.     santa_list = {"Nice": [], "Naughty": [], "Not found": []}
  14.  
  15.     for tuple_ in full_list:
  16.         if tuple_[0] not in modified_list:
  17.             modified_list[tuple_[0]] = []
  18.         modified_list[tuple_[0]].append(tuple_[1])
  19.  
  20.     for tuple_ in command:
  21.         arg = int(tuple_[0])
  22.         com = tuple_[2:]
  23.         type_kid = ["Naughty", "Nice"]
  24.  
  25.         if com == "Naughty":
  26.             santa_list, modified_list = put_kid_in_the_santa_list(santa_list, modified_list, arg, type_kid[0])
  27.  
  28.         elif com == "Nice":
  29.             santa_list, modified_list = put_kid_in_the_santa_list(santa_list, modified_list, arg, type_kid[1])
  30.  
  31.     for name in modified_list.values():
  32.         for i in name:
  33.             if i not in names.keys():
  34.                 names[i] = 0
  35.             names[i] += 1
  36.     for x, y in commands.items():
  37.         for a, b in names.items():
  38.             if x == a and b == 1:
  39.                 if y == "Naughty":
  40.                     santa_list["Naughty"].append(x)
  41.                     for k, v in modified_list.items():
  42.                         if x in v:
  43.                             v.remove(x)
  44.                 else:
  45.                     santa_list["Nice"].append(x)
  46.                     for k, v in modified_list.items():
  47.                         if x in v:
  48.                             v.remove(x)
  49.  
  50.     for r, t in modified_list.items():
  51.         if t:
  52.             santa_list["Not found"].extend(t)
  53.     final_result = ''
  54.  
  55.     for code, kid in santa_list.items():
  56.         if kid:
  57.             final_result += f"{code}: {', '.join(kid)}\n"
  58.     return final_result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement