PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
s = 'This is a sample sentence'
# dict comprehension
d = {w: len(w) for w in s.split(' ')}
print(d)
# ~~~
# with zip (will produce a zip object containing tuples with words and their lengths):
d = zip(s.split(), [len(w) for w in s.split()])
print(*d)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run