Python Dictionary Comprehension

前端 未结 8 1454
Happy的楠姐
Happy的楠姐 2020-11-21 13:10

Is it possible to create a dictionary comprehension in Python (for the keys)?

Without list comprehensions, you can use something like this:

l = []
fo         


        
8条回答
  •  滥情空心
    2020-11-21 13:45

    you can't hash a list like that. try this instead, it uses tuples

    d[tuple([i for i in range(1,11)])] = True
    

提交回复
热议问题