python - How can I remove tuples containing a specific value from a list? -


my list of tuples is:

[('huggies', 0.39), ('snugglers', 0.26), ('pie', 0.23), ('baby love', 0.23)] 

and need remove tuples not contain 0.23. how can this?

to compare every element of tuple:

>>> l = [('huggies', 0.39), ('snugglers', 0.26), ('pie', 0.23), ('baby love', 0.23)] >>> l = [t t in l if 0.23 in t] >>> l [('pie', 0.23), ('baby love', 0.23)] 

to compare second element:

>>> l = [('huggies', 0.39), ('snugglers', 0.26), ('pie', 0.23), ('baby love', 0.23)] >>> l = [t t in l if t[1] == 0.23] >>> l [('pie', 0.23), ('baby love', 0.23)] 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -