I'm having the following codes to test whether string 'h' is in any of the string in list aa. But it's giving me the TypeError: 'bool' object is not iterable. Why is that?
aa = ['hh', 'ii']
any('h' in aa)
Traceback (most recent call last):
File "<string>", line 2, in <module>
TypeError: 'bool' object is not iterable
any('h' in aa)
is giving you error exactly as showed in the error message because the conditional returns a boolean which is not an iterable needed for the any
function input.'h' in aa == False
'h' in ['hh', 'ii'] == False
any('h' in w for w in aa)
second_list = [['hh', 'ii'], ['gg', 'kk']]
any('h' in value for inner_list in second_list for value in inner_list)