+3 votes
in Programming Languages by (51.1k points)
How can I make all items a list keys of a dictionary?





{11: 'hello', 12: 'hello', 13: 'hello'}

1 Answer

+1 vote
by (157k points)
selected by
Best answer

The pythonic way to convert all elements of a list to keys of a dictionary is as follows:

>>> aa=[11,12,13]
>>> bb={v:'hello' for v in aa}
>>> bb
{11: 'hello', 12: 'hello', 13: 'hello'}
>>> bb[12]