您可以使用理解来使比较列表可用;还可以使用item in clean_compare检查名称中的项目:
>>> clean_compare = [i[13:-1] for i in compare]
>>> clean_compare
['bark', 'dentla', 'group', 'fusion']
>>> name
['group', 'sound', 'bark', 'dentla', 'test']
>>> {i:i in clean_compare for i in name} #for Python 2.7+
{'sound': False, 'dentla': True, 'bark': True, 'test': False, 'group': True}
如果要打印:
^{pr2}$
编辑:
或者,如果您只想打印它们,可以使用for循环轻松完成:
>>> name
['group', 'sound', 'bark', 'dentla', 'test']
>>> clean_compare
['bark', 'dentla', 'group', 'fusion']
>>> for i in name:
... print(i, i in clean_compare)
...
group True
sound False
bark True
dentla True
test False
对于你给定的数据,我会这样做:
输出为:
^{pr2}$您可以使用理解来使比较列表可用;还可以使用
item in clean_compare
检查名称中的项目:如果要打印:
^{pr2}$编辑:
或者,如果您只想打印它们,可以使用for循环轻松完成:
相关问题 更多 >
编程相关推荐