Dict and Set Comprehensions
Completed
Read a line of words. Print a dict mapping each word to its length (using a dict comprehension), then the sorted set of first letters (using a set comprehension).
Input
One line.
Output
Two lines.
Example
Input
apple banana avocado
Output
{'apple': 5, 'banana': 6, 'avocado': 7}
['a', 'b']
Editor
Python
Hints
{k: v for ...} builds a dict; {x for ...} builds a set.
Solution explanation
All four comprehension types share the same syntax: list, dict, set and generator.
Show solution
words = input().split()
print({w: len(w) for w in words})
print(sorted({w[0] for w in words}))