【发布时间】:2020-03-06 01:09:54
【问题描述】:
我有三个 CSV 文件,一个包含所有片段的列表,一个包含 M 类型片段列表,另一个包含 B 类型片段列表。这意味着第一个列表包含另外两个,但没有指定它们的类型。 我想在第一个列表中添加一行,使用 python 指定片段的类型,这意味着对于第一个列表中的每个片段,检查它是否在列表 M 中并在其类型列中添加一个 M,否则添加一个 B。 我的想法是创建一个字典列表(稍后我可以使用预先编写的 Python 库将其转换为 CSV),它看起来像这样:
l = [{'piece','type'}] # list of dictionaries
for c in allpieces: # this is the list of all pieces:
l[{'piece'}] = c['piece'] # adding the piece number to the list of dictionaries from the list of all pieces
for m in mlist: # list of pieces of type m
if c['piece'] == m['piece']: # check of piece is found in listm
l[{'type'}] = 'm' # Add an m in its column
else: l[{'type'}] = 'b' # otherwise add b
这段代码显然没有做任何事情,我需要帮助调试它。
【问题讨论】:
-
你能不能贴几行'allpieces',以便我更好地查看它以进行调试?