[Solved] Python: continue loop in one string if [closed]


There is no such syntax in Python.

The closest to one line you can get is two lines:

lst = [1, 1, 2, 2, 2, 3, 3]
uniq = []
for i in lst:
    if i not in uniq: uniq.append(i)    # <----
    else: continue                      # <----
    print(str(i))  # other useful code

Trying to put everything on one line (if i not in uniq: uniq.append(i); else: continue) would give you a syntax error).

The syntax you mentioned (uniq.append(i) if i not in uniq else continue) is a ternary expression, and as an expression, it cannot contain continue, which is a statement.

solved Python: continue loop in one string if [closed]