3 ms·
Pre 2.7, you can just give the dict constructor a generator of tuples: >>> dict((s, len(s)) for s in ["one", "two", "three"]) {'three': 5, 'two': 3, 'one':
by snprbob86 16y ago
Pre 2.7, you can just give the dict constructor a generator of tuples:
>>> dict((s, len(s)) for s in ["one", "two", "three"])
{'three': 5, 'two': 3, 'one': 3}
- calibraxis 16y agoThank you very much! Lack of simple dict-building had been bothering me.