#create a listl = [("x", 1), ("x", 2), ("x", 3), ("y", 1), ("y", 2), ("z", 1)]d = {}for a, b in l: d.setdefault(a, []).append(b)print (d)
本文共 194 字,大约阅读时间需要 1 分钟。
#create a listl = [("x", 1), ("x", 2), ("x", 3), ("y", 1), ("y", 2), ("z", 1)]d = {}for a, b in l: d.setdefault(a, []).append(b)print (d)
转载于:https://www.cnblogs.com/sea-stream/p/9944986.html