我在列表中有一个列表:
a = [
[123123, 'juststring', '129.123.41.4'],
[456456, 'usrnm', '129.123.41.4'],
[78970, 'Something', '129.123.41.4']
]
我还有另一个列表:
b = [123123, 354634, 54234, 6734]
如果b
在a
中包含数字,则必须输入'YES'或'NO'
输出:
a = [[123123, 'juststring', '129.123.41.4', 'YES'], [456456, 'usrnm', '129.123.41.4', 'NO'], [78970, 'Something', '129.123.41.4', 'NO']]
这是我的代码:
for i in range(len(tbl_list)):
for l in tbl_list:
for p in pid:
if int(l[0]) == int(p):
tbl_list[i].append('YES')
break
else:
tbl_list[i].append('NO')
break
def draw_table():
global tbl_list
global pid
for i in range(len(tbl_list)):
for l in tbl_list:
for p in pid:
if int(l[0]) == int(p):
tbl_list[i].append('YES')
break
else:
tbl_list[i].append('NO')
break
tbl.add_row(l)
print(tbl_list)
print(tbl.draw())
tbl.reset()
tbl.header(Heading)
答案 0 :(得分:2)
您可以这样做:
a = [[123123, 'juststring', '129.123.41.4'], [456456, 'usrnm', '129.123.41.4'], [78970, 'Something', '129.123.41.4']]
b = [123123, 354634, 54234, 6734]
for list_a in a:
if any(pid == list_a[0] for pid in b):
list_a.append('YES')
else:
list_a.append('NO')
print(a)