python 调试用代码
生成随机由字典构成的列表数据
import random
import string
def generate_random_string(length):
"""生成随机字符串"""
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
def generate_random_data(num_records):
"""生成指定数量的随机字典数据"""
data = []
for _ in range(num_records):
record = {
'id': random.randint(1, 1000000),
'age': random.randint(18, 80),
'name': generate_random_string(10)
}
data.append(record)
return data
if __name__ == '__main__':
num_records = 10000
random_data = generate_random_data(num_records)
print(random_data)
License:
CC BY 4.0