默认/没有足够的值来解压缩

  • 本文关键字:解压缩 默认 python
  • 更新时间 :
  • 英文 :


这可能是一个愚蠢的问题,但是:我有这段代码工作正常,直到我尝试添加ml。我尝试了几种方式,但是

init_dict = []
with open("example.csv", "r") as new_data:
reader = csv.reader(new_data, delimiter=',', quotechar='"')
for row in reader:
if row:
columns = [row[0], row[1], row[3]]
init_dict.append(columns)
result = defaultdict(list)
for ean, price, ml in init_dict:
result[ean].append(price)
result[ean].append(ml)
for ean, price, ml in result.items():
print(ean, " // " . join(price), "::". join(ml))

我需要将 ml 信息添加到我当前的输出中,如下所示:

676543 : 6,7 // 6,7
786543 : 3
4543257 : 7,8 // 9,0

等。。。谢谢你的帮助

你的result变量是两个项目列表的字典,所以你应该像这样解压缩它的项目:

for ean, (price, ml) in result.items():

最新更新