我正在查看项目是否在列表列表中。
List1 = [['a','b','c'],['d','e','f'],['g','h','i']]
如果b
在列表中的任何列表中,则打印True
。否则,打印False
。
执行此操作的Python方法是什么?
答案 0 :(得分:9)
尝试一下:
# check element exists in list of list or not?
result = any("b" in sublist for sublist in List1)
# printing result
print(str(result))
答案 1 :(得分:0)
我扮演傻瓜...
<source>: In function 'int main()':
<source>:44:29: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
44 | Lebensmittel bananen(2, "Bananen", 0.75);
| ^~~~~~~~~
<source>:55:22: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
55 | Moebel schraenke("Schraenke", 250.0);
| ^~~~~~~~~~~