dvas0004 / NerdNotes

A collection of notes: things I'd like to remember while reading technical articles, technical questions I couldn't answer, and so on.
12 stars 0 forks source link

Python dictionary (list) comprehensions #117

Open dvas0004 opened 4 years ago

dvas0004 commented 4 years ago

It's possible to generate a dictionary using comprehensions:

t = ["1", "234", "45"]
a = { keyName: len(keyName) for keyName in t }
print(a)
# prints: {'1': 1, '234': 3, '45': 2}