首页 > 解决方案 > If any of the lines in a list of lines contains a substring

问题描述

Python 3.7.3

I have a list of lines and I want a single statement to test if a value is contained by any of the lines:

 >>> data=[["red blue green yellow"],["peter ann jack beatrice"]]
 >>> "ann" in data
 False

I want this to be True.

Is there a single statement test, without explicit iteration, that will return True for "ann" or any of the single values in the two lists.

标签: pythonlist

解决方案


'ann' in ' '.join(sum(data,[]))

推荐阅读