0
我只是从Stackoverflow学习一个新的方法zip(),但它不能正常工作。我无法将2个列表组合成字典使用zip()
def diction():
import random
import string
import itertools
dictionary_key={}
upper_list = []
string_dictionary_upper = string.ascii_uppercase
for n in string_dictionary_upper:
upper_list.append(n)
upper_list_new = list(random.shuffle(upper_list))
dictionary_key = dict(zip(upper_list, upper_list_new))
diction()
错误代码是'NoneType'对象不可迭代'。但我找不到原因。
upper_list_new = upper_list[:] #create a copy
random.shuffle(upper_list_new) #shuffle the copy
结果就可以:
'random.shuffle(upper_list)'不*返回*列表 - 它将一个列表重新排序并返回'None' –
谢谢,我可以使用random.simple来返回一个新列表吗? –