我创建了一个word_name的字典,我希望这个字典每次生成的随机内容都可以生成一个独立的字典,然后将这些字典归到word_all字典中进行存储
#!/usr/bin/python3
import random
def create_word():
i = 0
word_name = {}
word_all = {}
word_num = random.randint(0,100)
while i < word_num:
a = 'a'+str(i)
xx = {a:123}
word_name.update(xx)
i = i + 1
print(word_name)
create_word()
是这样吗?
import random
def create_word():
i = 0
word_name = {}
word_all = {}
word_num = random.randint(0,100)
while i < word_num:
a = 'a'+str(i)
xx = {a:random.randint(0,100)}
word_name.update(xx)
i = i + 1
print(word_name)
create_word()
是想让它变成嵌套字典,比如{a:{xxx:111,sss:222},b:{zzz:222,sss:333}}