SimeonTs

SUPyF Dictionaries - 09. Wardrobe

Jun 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. """
  2. Dictionaries and Functional Programming
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/945#8
  4.  
  5. SUPyF Dictionaries - 09. Wardrobe
  6.  
  7. Problem:
  8. You just bought a new wardrobe. The weird thing about it is that it came prepackaged with a big box of clothes
  9. (just like those refrigerators, which ship with free beer inside them)! So, you’ll need to find something to wear.
  10. Input
  11. On the first line of the input, you will receive n –  the number of lines of clothes,
  12. which came prepackaged for the wardrobe.
  13. On the next n lines, you will receive the clothes for each color in the format:
  14. - “{color} -> {item1},{item2},{item3}…”
  15. If a color is added a second time, add all items from it and count the duplicates.
  16. Finally, you will receive the color and item of the clothing, that you need to look for.
  17. Output
  18. Go through all the colors of the clothes and print them in the following format:
  19. {color} clothes:
  20. * {item1} - {count}
  21. * {item2} - {count}
  22. * {item3} - {count}
  23. * {itemN} - {count}
  24. If the color lines up with the clothing item, print “(found!)” alongside the item. See the examples to better
  25. understand the output.
  26. Example:
  27. INPUT:
  28. 4
  29. Blue -> dress,jeans,hat
  30. Gold -> dress,t-shirt,boxers
  31. White -> briefs,tanktop
  32. Blue -> gloves
  33. Blue dress
  34. OUTPUT:
  35. Blue clothes:
  36. * dress - 1 (found!)
  37. * jeans - 1
  38. * hat - 1
  39. * gloves - 1
  40. Gold clothes:
  41. * dress - 1
  42. * t-shirt - 1
  43. * boxers - 1
  44. White clothes:
  45. * briefs - 1
  46. * tanktop - 1
  47. """
  48. colors = {}
  49.  
  50. for each_time in range((int(input()))):
  51.     command = [item for item in input().split(" -> ")]
  52.     values = [item for item in command[1].split(",")]
  53.  
  54.     for value in values:
  55.         if command[0] not in colors:
  56.             colors[command[0]] = {}
  57.             colors[command[0]][value] = 1
  58.         elif command[0] in colors:
  59.             if value not in colors[command[0]]:
  60.                 colors[command[0]][value] = 1
  61.             elif value in colors[command[0]]:
  62.                 colors[command[0]][value] += 1
  63.  
  64. command_check = [item for item in input().split(" ")]
  65.  
  66. for color, item in colors.items():
  67.     print(f"{color} clothes:")
  68.     for values, count in item.items():
  69.         if command_check[0] == color and command_check[1] == values:
  70.             print(f"* {values} - {count} (found!)")
  71.         else:
  72.             print(f"* {values} - {count}")
Add Comment
Please, Sign In to add comment