python list add if not present

lst.append(3) if 3 not in lst else lst

Here is what the above code is Doing:
1. It’s creating an empty list called lst.
2. It’s appending the number 1 to the list if the number 1 is not already in the list.
3. It’s appending the number 2 to the list if the number 2 is not already in the list.
4. It’s appending the number 3 to the list if the number 3 is not already in the list.

The code above is equivalent to the following:

lst = []
if 1 not in lst:
lst.append(1)
if 2 not in lst:
lst.append(2)
if 3 not in lst:
lst.append(3)