我必須刪除行列表中項目的索引,其中lines[0]
的項目不在標題中。Python:按索引彈出列表列表中的項目
輸入如下:
headers = ['internal_id', 'default_code', 'ean13', 'supplier_id', 'product_qty']
lines = [['default_code', 'fld_code', 'test'],[1212, 4545, 'test1'],[45, 787, 'test2']]
預期輸出如下:
lines = [['default_code'],[1212],[45]]
我已經試過到目前爲止做的是在這裏:
for x in lines[0]:
if x not in headers:
for line in lines[0]:
line.pop(line.index(x))
print lines
這尚未產生所需的產出。請幫助。
既然你改正了語言凱文Cruijssen,我不明白...對我來說「預期的輸出」是不兼容的解釋「我必須刪除行列表中的項目由行項目索引[0]不在標題中「 – Vince