I would like to make the for... if
in the following code into one line:
cities = ["Berlin", "Berlin", "Berlin", "London"]
unique_cities = []
for city in cities:
if city not in unique_cities:
unique_cities.append(c)
print unique_cities
I imagine something like this:
unique_cities = [city for city in cities if city not in unique_cities]
which of course doesn't work because unique_cities
is not defined in that loop.
How would I make a one-liner out of this?