How to declare many variables?

前端 未结 5 911
醉话见心
醉话见心 2020-12-11 13:22

Here is the letters:

letters=\'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\'

I made a list of it with this:

<         


        
5条回答
  •  北海茫月
    2020-12-11 13:47

    An alternative to list comprehensions is to use map

    In [841]: letters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
    
    In [842]: chars = list(map(lambda l: 0, letters))
    

    Or if you want a dict like the other answers are suggesting

    In [844]: dict(map(lambda l: (l, 0), letters))
    

    I generally find list/dict comprehensions to both be faster and more readable (to me at least). This is just a different approach

提交回复
热议问题