自学python,这是我发表的第一篇python博客
列表为[“a”,”j”,”g”,”h”,”k”,”i”,”l”,”f”,”v”,”b”,”2”,”5”,”x”]
import numpy as np
word_list = ["a","j","g","h","k","i","l","f","v","b","2","5","x"]
len_list = range(len(word_list))
#将列表生成字典,key为元列表的id序号,values为对应序号的字母,先使用zip将列表组合,再用dict将列表化为字典,id在前,字符在后
word_dict = dict(zip(word_len,word_list))
result = []
random_list = np.random.randint(0,13,5)
random_list.sort()
def random_dictvalue(random_list):
for i in random_list:
result.append(word_dict[i])
return result
random_dictvalue(random_list)
print (result)