【发布时间】:2018-09-05 14:00:11
【问题描述】:
我正在尝试找到使用 Python 将列表中的每个元素与列表列表中的每个元素匹配的最有效方法。例如输入:
>>>myList = [['hi', 'no', 'bye', 'Global', 24],['morning', 'X', 'place'],['so', 'large', 'mall','test'], ['hi', 'X', 'place', 'bye']]
>>>check_against_myLIst = ['bye','place','hi','australia']
现在我不确定最好的方法是使用 map 函数、for 循环还是任何其他 python 数据分析方法。
输出需要转换成数据帧,输出就是这样。
Index Value Result
0 ['hi', 'no', 'bye', 'Global', 24] True
1 ['morning', 'X', 'place'] True
2 ['so', 'large', 'mall','test'] False
3 ['hi', 'X', 'place', 'bye'] True
谢谢!
【问题讨论】:
-
永远不要给你的变量命名为python的内置函数。
-
我认为您可能对元组和列表有些混淆...
-
为什么索引 3 的结果为 True?
-
@timgeb 因为索引 3 的值包含“hi”和“bye”。要使其为真,该值必须包含存在于
check_against_myList中的元素 -
@helloWorld 好的。下次请在问题中添加您想要做什么的说明。
标签: python list data-analysis