I have a list
in Python,
a=[("title","artiste"),
("titl","artste"),
("ttle","titl")]
I want to create a second list; the second list should not include the search term.
How to search whether "titl"
is in the first string of the tuples (just the first string, not the second string) of the three tuples or not?
Use any()
and a generator expression to determine whether the first ( [0]
) element of any of the tuples ( t
) in
list
a
equal 'titl'
:
>>> any((t[0] == 'titl' for t in a))
True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.