I am given:
list = [{'a','b'},{'c','d'}]
and I want to know if 'a' is in the list.
should I first unpack the list as here to new_list and the use 'a' in new_list
Or is there a shorter way (without importing modules)
This is one approach using any
.
Ex:
l = [{'a','b'},{'c','d'}]
print( any(map(lambda x: "a" in x, l)) )
Output:
True
Hope it's solve it. I write it on a function to use "return" keyword
def a_is_there():
lists = [{'a','b'},{'c','d'}]
for list in lists:
if "a" in list:
print("True")
return True
print("False")
return False
a_is_there()
Thanks