Joh*_*lba 3 python tuples substring
检查字符串元组中是否出现多个子字符串的最优雅方法是什么?
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
Run Code Online (Sandbox Code Playgroud)
any(substr in str_ for str_ in tuple_)
Run Code Online (Sandbox Code Playgroud)
你可以从那个开始,也可以看看all()
。