Keyword Collector
Completed
Write build_profile(name, **info) returning a dict with name plus every extra keyword argument. Read n lines key=value, pass them as keyword arguments with name "guest", and print the dict items sorted by key as key: value.
Input
Line 1: n. Then n lines key=value.
Output
One line per key.
Example
Input
2 age=30 city=Pune
Output
age: 30 city: Pune name: guest
Editor
Python
Hints
**info collects keyword arguments into a dict.
**extra in a call unpacks a dict into keyword arguments.
Solution explanation
**kwargs is the keyword equivalent of *args.
Show solution
def build_profile(name, **info):
profile = {"name": name}
profile.update(info)
return profile
n = int(input())
extra = dict(input().split("=") for _ in range(n))
profile = build_profile("guest", **extra)
for key in sorted(profile):
print(f"{key}: {profile[key]}")