Pythonic way to combine FOR loop and IF statement

You can use generator expressions like this:

gen = (x for x in xyz if x not in a)

for x in gen:
    print(x)

Leave a Comment

error code: 523