【发布时间】:2018-09-05 06:39:37
【问题描述】:
>>> from string import ascii_lowercase
>>> from random import shuffle
>>> shuffle(alp)
>>> alp
['n', 'c', 'q', 'l', 's', 't', 'w', 'a', 'o', 'r', 'g', 'u', 'd', 'm', 'k',
'p', 'x', 'v', 'z', 'y', 'j', 'h', 'i', 'f', 'e', 'b']
>>> ck = {x:alp.pop() for x in ascii_lowercase}
>>> ck
{'a': 'b', 'b': 'e', 'c': 'f', 'd': 'i', 'e': 'h', 'f': 'j', 'g': 'y', 'h':
'z', 'i': 'v', 'j': 'x', 'k': 'p', 'l': 'k', 'm': 'm', 'n': 'd', 'o': 'u',
'p': 'g', 'q': 'r', 'r': 'o', 's': 'a', 't': 'w', 'u': 't', 'v': 's', 'w':
'l', 'x': 'q', 'y': 'c', 'z': 'n'}
什么 make 以及为什么 alp 列表从 alp 的最后一个列表元素分配给 ck?比如“a:b b:e...”
【问题讨论】:
-
因为 pop 就是这样做的......
标签: python list dictionary