I'm looking to see if item is in list of list.
List1 = [['a','b','c'],['d','e','f'],['g','h','i']]
If b
is in any of the list in a list, then print True
. Else, print False
.
What's the pythonic way to do this?
I'm looking to see if item is in list of list.
List1 = [['a','b','c'],['d','e','f'],['g','h','i']]
If b
is in any of the list in a list, then print True
. Else, print False
.
What's the pythonic way to do this?
Try this:
# check element exists in list of list or not?
result = any("b" in sublist for sublist in List1)
# printing result
print(str(result))
I'll play the fool...
>>> 'b' in sum(List1, [])
True
>>> 'B' in sum(List1, [])
False