Advertisement
llirik

Untitled

Dec 7th, 2020 (edited)
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. def ex2(dic):
  2.     unique = phones_removed = []
  3.     for i in range(len(dic)):
  4.         _name_city = dic[i]['name'] + dic[i]['city']
  5.         if _name_city not in unique:
  6.             unique.append(_name_city)
  7.         else:
  8.             _phones = dic[i]['phones']
  9.             for phone in _phones:
  10.                 if phone not in phones_removed:
  11.                     phones_removed.append(phone)
  12.             dic[i].clear()
  13.     return dic
  14.  
  15.  
  16. def main():
  17.     phones_list = [{'name': 'Ivan', 'city': 'Moscow', 'phones': ['232-19-55', '+7 (916) 230-00-75']},
  18.                    {'name': 'Anna', 'city': 'Samara', 'phones': ['200-11-15']},
  19.                    {'name': 'Anna', 'city': 'Vologda', 'phones': ['+7 (931) 711-00-75']},
  20.                    {'name': 'Nikolay', 'city': 'Moscow', 'phones': ['+7 (916) 778-71-05', '331-66-11', '783-33-85']},
  21.                    {'name': 'Ivan', 'city': 'Moscow', 'phones': ['+7 (916) 205-41-05', '232-19-55']},
  22.                    {'name': 'Anna', 'city': 'Samara', 'phones': ['+7 (916) 105-13-56']}
  23.                    ]
  24.     new_dict = ex2(phones_list)
  25.     print(new_dict)
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement