简体   繁体   English

将列表中的每个元素与另一个元素进行比较

[英]Compare each of the elements of a list with another one

How can I iterate or loop through each of the elements of a list with another list?如何使用另一个列表迭代或循环列表的每个元素?

If I use the following:如果我使用以下内容:

"for m, e in zip (arrayMaster, arrayExamples):"

I get a - A, b - B, c - C我得到a - A,b - B,c - C

I pretend to get this: a - A, a - B, a - C, b - A, b - B, b - C....我假装明白:a - A,a - B,a - C,b - A,b - B,b - C....

My ultimate goal is to compare two lists and if the characters in list "e" are found in list "m" it will output a True message.我的最终目标是比较两个列表,如果在列表“m”中找到列表“e”中的字符,它将 output 一条 True 消息。

Example:例子:

List m

Sbh 411,
Sbh 25 Str,
Sba 3 Str Sba 3 Str,
A 203,
Sbh 611,
Sbm 800,
O 19 MozartWA,
BUS BusoniF Sbm 800 Kin,
Sbb 2 Sch,
Sbb 2 Men,
Sbc 22,
Sbc 21,
Sbh 9,
Sbc 31 Ede,
Sbc 22 Hey,
...

List e

Sba 1,
Sba 2,
Sba 3,
Sba 4,
Sba 5,
Sba 6,
Sba 7,
Sba 8,
Sba 9,
Sba 10,
Sba 11,
Sba 12,
Sba 13,
Sba 14,
Sba 15,
Sba 16,
Sba 17,
...

No need to iterate through each elements, just use the built-in in :无需遍历每个元素,只需使用内置的in

for i, m in enumerate(arrayMaster):
    if m in arrayExamples:
        print(f'arrayMaster index: {i}')
        print(f'arrayExamples index: {arrayExamples.index(m)}')

Simple way would be简单的方法是

for m in M:
    if m in E:
        print(m, True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 比较一个嵌套列表的元素和另一个嵌套列表的元素 - Compare elements of one nested list with another nested list 用另一个迭代列表中的每个元素替换列表中的每个元素 - Replace each elements of a list by another iterating each one of them 将一个列表的每个字符串元素连接到另一个列表的所有元素 - Concatenate each string element of one list to all elements of another list 检查一个列表的每个元素是否是另一个列表的所有元素的倍数 - Check if each element of one list is a multiple of all the elements of another list 如何进入嵌套列表中的每个元素并将其与另一个列表中所有元素的等效项进行比较? - How to get into each element in a nested list and compare it with the equivalent in all elements in another list? Python:将列表中的元素相互比较 - Python: Compare elements in a list to each other 在python中一一比较列表中的元素 - compare elements of a list one by one in python 如何将列表中的元素与另一个元素是字典的列表中的元素进行比较? - How compare elements in a list with elements in another list whose elements are dicts? 将一本字典的每个元素与它的其他元素进行比较-查找相似的元素 - Compare each elements of one dictionary to other elements of it - find the similar elements 将两个数组及其元素相互比较 - Compare two arrays and their elements against one another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM