我有三个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
这段代码显然没有做任何事情,我需要帮助对其进行调试。