I have some problem with the "any" syntax. I have two lists.
mainseq = ["hali", "hulu", "habi"]
seq = ["a", "b", "c", "d"]
I want to find if elements in seq
exist in mainseq
.
for each in seq:
if any(each in halum for halum in mainseq):
print each
This gives me "a" and "b" as expected. But when I remove the "any" syntax, I get all the values in seq
, even though "c" and "d" are not there in mainseq
.
for each in seq:
if (each in halum for halum in mainseq):
print each
What is happening behind the scenes with and without the "any" function?