String contains all the elements of a list

前端 未结 5 998
暖寄归人
暖寄归人 2021-01-05 18:32

I am shifting to Python, and am still relatively new to the pythonic approach. I want to write a function that takes a string and a list and returns true if all the elements

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 19:05

    >>> all(x in 'tomato' for x in ['t','o','m','a'])
    True
    >>> all(x in 'potato' for x in ['t','o','m','a'])
    False
    

提交回复
热议问题