I know that following is list comprehension syntax:
List2 = [item for item in List1 if item=='test']
However for nested list comprehension, the syntax changes to how it would have appeared in a normal program:
List3 = [ y for x in toplevelForLoop for y in x ]
The if loop can appear after the first or 2nd for loop as per logic but the sequence is like how it would be in a normal program.
Is below acceptable? I am trying to check if item in ListB is contained within item in ListA
Code:
for itemA in ListA:
if any([ itemB in itemA for itemB in ListB ])
Is the above code equivalent to the below?
Code:
if any([ itemB in itemA for itemA in ListA for itemB in ListB ])