Advertisement
SimeonTs

SUPyF Dictionaries - 05. Mixed Phones

Jun 23rd, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. """
  2. Dictionaries and Functional Programming
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/945#4
  4.  
  5. SUPyF Dictionaries - 05. Mixed Phones
  6.  
  7. Problem:
  8. You will be given several phone entries, in the form of strings in format:
  9. {firstElement} : {secondElement}
  10. The first element is usually the person’s name, and the second one – his phone number.
  11. The phone number consists ONLY of digits, while the person’s name can consist of any ASCII characters.
  12. Sometimes the phone operator gets distracted by the Minesweeper she plays all day, and gives you first the phone,
  13. and then the name. e.g. : 0888888888 : Pesho. You must store them correctly, even in those cases.
  14. When you receive the command “Over”, you are to print all names you’ve stored with their phones.
  15. The names must be printed in alphabetical order.
  16. Examples:
  17.  
  18. Input:
  19. 14284124 : Alex
  20. Gosho : 088423123
  21. Ivan : 412048192
  22. 123123123 : Nanyo
  23. Pesho : 150925812
  24. Over
  25.  
  26. Output:
  27. Alex -> 14284124
  28. Gosho -> 88423123
  29. Ivan -> 412048192
  30. Nanyo -> 123123123
  31. Pesho -> 150925812
  32. """
  33. phonebook = {}
  34.  
  35. while True:
  36.     command = [item for item in input().split(" : ")]
  37.     if "Over" in command:
  38.         break
  39.     if command[1].isdigit():
  40.         phonebook[command[0]] = command[1]
  41.     else:
  42.         phonebook[command[1]] = command[0]
  43.  
  44. for name, number in sorted(phonebook.items()):
  45.     print(f"{name} -> {number}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement