I just started learning Python today.
I have a list:
[text:u'Oranges', text:u'Apples', empty:'', empty:'']
How do I get the last non-empty item in a list? In this case, ‘Apples’.
I see in Get first non-empty string from a list in python, they get the first non-empty value. Not sure how to get the last.
If you really have a dictionary, use
reversed(dictionary.values()), but keep in mind that anything you do to the dictionary can change it’s ordering, and it’s not ordered in a consistent way between different versions of Python even for a given state.Use an
OrderedDictif you want the keys kept in insertion order.