collections.defaultdict

Lab Python Intermediate 20 points

Read n lines city person. Using defaultdict(list), print each city (sorted) followed by its people (sorted).

Input

Line 1: n. Then n lines.

Output

One line per city.

Example

Input

4
pune zed
delhi amy
pune bob
goa cy

Output

delhi amy
goa cy
pune bob zed
Sample input available Sample output available
Editor
Python

Hints

defaultdict(list) creates an empty list the first time a key is used.

Solution explanation

defaultdict removes the "is this key here yet?" check.

Show solution
from collections import defaultdict

by_city = defaultdict(list)
for _ in range(int(input())):
    city, person = input().split()
    by_city[city].append(person)
for city in sorted(by_city):
    print(city, *sorted(by_city[city]))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD