>>>
>>> T = 'oti'
>>> S = ['cat','tor','tutorial','item','aba','tori']
>>> t = set(T)
>>> t
{'o', 't', 'i'}
>>> for thing in S:
... if t.issubset(thing):
print(thing)
tutorial
tori
>>>
如果有重复的字符,这将不起作用。你知道吗
>>> q = set('otti')
>>> for thing in S:
... if q.issubset(thing):
print(thing)
tutorial
tori
>>>
使用all
>>>
>>> for thing in S:
... if all(c in thing for c in T):
print(thing)
tutorial
tori
>>>
使用sets进行成员资格测试。你知道吗
如果有重复的字符,这将不起作用。你知道吗
使用
all
相关问题 更多 >
编程相关推荐