Reputation: 10740
I have such list of tuples:
lst = [(10, u'1.15', u'1.15'), (5, 0, u'1.875'), (3, u'2.28', u'2.28')]
and I want to get the new one with just second and third element of each tuple, which not equal to the 0, in other words, I need something like:
new_lst = [u'1.15', u'1.15',u'1.875', u'2.28', u'2.28']
Thanks for your answers.
Upvotes: 1
Views: 1313
Reputation: 114035
>>> L = [(10, u'1.15', u'1.15'), (5, 0, u'1.875'), (3, u'2.28', u'2.28')]
>>> answer = []
>>> for tup in L:
... answer.extend([i for i in tup[1:] if i])
...
>>> answer
[u'1.15', u'1.15', u'1.875', u'2.28', u'2.28']
Hope this helps
Upvotes: 0
Reputation: 799520
>>> [x for y in lst for x in y[1:3] if x]
[u'1.15', u'1.15', u'1.875', u'2.28', u'2.28']
Upvotes: 2