我有一个代码,用于检查字符串是否在字符串列表中,如
<ElementList>
<superparent id="1462682">
<Element>
<Date>2017-12-18</Date>
<SuperParent>1462682</SuperParent>
<Id>1462682</Id>
<Phase>Completed</Phase>
</Element>
<Element>
<Date>2017-12-16</Date>
<SuperParent>1462682</SuperParent>
<Id>1462683</Id>
<Status>Normal</Status>
</Element>
<Element>
<Date>2017-12-15</Date>
<SuperParent>1462682</SuperParent>
<Id>1462687</Id>
<Status>Normal</Status>
</Element>
</superparent>
<superparent id="1462812">
<Element>
<Date>2017-12-19</Date>
<SuperParent>1462812</SuperParent>
<Id>1462812</Id>
<Status>Normal</Status>
</Element>
<Element>
<Date>2017-12-18</Date>
<SuperParent>1462812</SuperParent>
<Id>1462813</Id>
<Status>Normal</Status>
</Element>
<Element>
<Date>2017-12-17</Date>
<SuperParent>1462812</SuperParent>
<Id>1462817</Id>
<Status>Normal</Status>
</Element>
</superparent>
如果在列表中找到字符串,则返回 for a in array:
if x in a:
return True
return False
和True
。我想知道它是否可以用一行代码编写。