Programming-Idioms

History of Idiom 42 > diff from v34 to v35

Edit summary for version 35 :
[Python] asdsadasd

Version 34

2019-10-04, 23:03:04

Version 35

2019-11-18, 14:37:23

Idiom #42 Continue outer loop

Print each item v of list a which in not contained in list b.
For this, write an outer loop to iterate on a and an inner loop to iterate on b.

Illustration

Idiom #42 Continue outer loop

Print each item v of list a which in not contained in list b.
For this, write an outer loop to iterate on a and an inner loop to iterate on b.

Illustration
Code
for v in a:
    try:
        for u in b:
            if v == u:
                raise Exception()
        print(v)
    except Exception:
        continue
Code
for v in a:dsasddasdasdasdasd
    try:
        for u in b:
            if v == u:
                raise Exception()
        print(v)
    except Exception:
        continue
Comments bubble
Note that using two loops like this in python is by itself very un-idiomatic. Also one would be wise to define a custom exception to avoid hiding "real" exceptions.
Comments bubble
Note that using two loops like this in python is by itself very un-idiomatic. Also one would be wise to define a custom exception to avoid hiding "real" exceptions.