stock_list = [
['股票代码', '股票名称', '当前价', '涨跌额', '涨跌幅', '年初至今', '成交量', '成交额', '换手率', '市盈率(TTM)', '股息率', '市值'],
['SH601778', 'N晶科', '6.29', '+1.92', '+43.94%', '+43.94%', '259.66万', '1625.52万', '0.44%', '22.32', '-', '173.95亿'],
['SH688566', '吉贝尔', '52.66', '+6.96', '+15.23%', '+122.29%', '1626.58万', '8.09亿', '42.29%', '89.34', '-', '98.44亿']
]
single_stock_dic = {} #单一股票信息,格式为{'股票代码':'SH603313',……}
new_stock_list = []
# 将每一条股票信息存入相应的stock_dic[股票代码]中
for i in range(1, len(stock_list)):
for j in range(len(stock_list[0])):
single_stock_dic[stock_list[0][j]] = stock_list[i][j]
print(single_stock_dic)
new_stock_list.append(single_stock_dic)
print(new_stock_list)
运行代码之后,print(single_stock_dic)
和print(new_stock_list)
输入的内容并不一致,这是什么原因呢?我通过debug发现是两层循环的问题,但是并不清楚具体为什么会是这样