默认字典/按分钟排序

Default Dict / Sort by min

提前感谢您的帮助。到目前为止我有这段代码:

with open("clean_result.csv", "r", encoding="utf-8", errors="ignore") as 
new_data:
reader = csv.reader(new_data, delimiter=',', quotechar='"')
for row in reader:
    if row:
        columns = [row[0], row[1]]
        init_dict.append(columns)

for ean, price in init_dict:
    result[ean].append(price)

然后我用这条线得到每个价格的最小值:

maxitems = {ean : min(result[ean]) for ean in result}

当前输出:{'8714789828558': '5,51', '3326100000182': '15,00', '3286010016683': '3,93' (...) }


我想要的是添加行[2] 并获取附加信息,但仅限于最低价格值。

期望输出:{'8714789828558': '5,51', 'A', '3326100000182': '15,00', 'B' '3286010016683': '3,93', 'C' (...) }

我试过了:

for row in reader:
    if row:
        columns = [row[0], row[1], row[2]]
        init_dict.append(columns)

for ean, price, desc in init_dict:
       result[ean].append(price)
       result[ean].append(desc)

maxitems = {ean : min(result[ean]) for ean in result}

但是输出是这样的。一半数据丢失:

{'8714789828558': 'A', '3326100000182': 'B' '3286010016683': 'C' (...) }

我可能误解了一些东西所以请任何帮助感谢

from operator import itemgetter
from collections import defaultdict

result = defaultdict(list)

for row in reader:
    if row:
        result[row[0]].append((row[1], row[2]))

minitems = {ean : min(prices, key = itemgetter(0)) for ean, prices in result.iteritems()}