Logo

Programming-Idioms

History of Idiom 42 > diff from v30 to v31

Edit summary for version 31 by sgdpk:
[Python] Forgot print statement

Version 30

2019-09-27, 03:11:50

Version 31

2019-09-27, 03:13:07

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:
    for v_ in b:
        if v == v_:
            continue

# More idiomatic solution for this specific problem
# 
# for v in a:
#     if v not in b:
#        print(v)
Code
for v in a:
    for v_ in b:
        if v == v_:
            continue
        print(v)

# More idiomatic solution for this specific problem
# 
# for v in a:
#     if v not in b:
#        print(v)