📌  相关文章
📜  python返回包含子字符串的第一个列表元素 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:12.343000             🧑  作者: Mango

代码示例1
# Example usage:
your_list = ['The answer to', 'the ultimate question', 'of life', 
     'the universe', 'and everything', 'is 42']

[idx for idx, elem in enumerate(your_list) if 'universe' in elem][0]
--> 3 # The 0-based index of the first list element containing "universe"