gpt4 book ai didi

python:检查子字符串是否在字符串元组中

转载 作者:行者123 更新时间:2023-11-28 22:33:32 27 4
gpt4 key购买 nike

检查字符串元组中是否出现多个子字符串的最优雅方法是什么?

tuple = ('first-second', 'second-third', 'third-first') 
substr1 = 'first'
substr2 = 'second'
substr3 = 'third'
#if substr1 in tuple and substr2 in tuple and substr3 in tuple:
# should return True

最佳答案

any(substr in str_ for str_ in tuple_)

您可以从它开始,然后查看 all()

关于python:检查子字符串是否在字符串元组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39807545/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com