列表推导式 随机数 生成字典


import random
def add_data(collection):
first_name = ["陈","张","李","王","赵"]
second_name = ["冰","鑫","程","爱","暖"]
third_name = ["强","国","明","风","芬"]
data = [
{"_id":int("1000"+str(i)),
"name":random.choice(first_name)+
random.choice(second_name)+
random.choice(third_name),
"age":random.randint(16,60),
"high":random.randint(170,190),
"list":list(random.randint(1,200) for i in range(10))
} for i in range(5)
]

posted on 2019-07-21 19:12  潇潇无敌  阅读(734)  评论(0编辑  收藏  举报

导航