I'm currently learning Python.
How do I put this:
dates = list()
for entry in some_list:
entry_split = entry.split()
if len(entry_split) >= 3:
date = entry_split[1]
if date not in dates:
dates.append(date)
into a one-liner in Python?
Instead of a 1-liner, probably it's easier to understand with a 3-liner.
table = (entry.split() for entry in some_list)
raw_dates = (row[1] for row in table if len(row) >= 3)
# Uniquify while keeping order. http://stackoverflow.com/a/17016257
dates = list(collections.OrderedDict.fromkeys(raw_dates))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With