Advertisement
ElenaSokol

Untitled

Dec 7th, 2022
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def forecast(**data):
  2.     locations = {}
  3.     result = []
  4.  
  5.     for key, value in data.items():
  6.         if key not in locations:
  7.             locations[key] = []
  8.  
  9.         locations[key].append(value)
  10.  
  11.     locations = sorted(locations.items(), key=lambda x: (x[0]))
  12.  
  13.     for location, values in locations:
  14.         result.append(f"{location}:")
  15.  
  16.         for value in sorted(values):
  17.             result.append(f"-{value}")
  18.  
  19.     return "\n".join(result)
  20.  
  21.  
  22. print(forecast(
  23.     ("Sofia", "Sunny"),
  24.     ("London", "Cloudy"),
  25.     ("New York", "Sunny")))
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement