How to check if one of the following items is in a list?

前端 未结 14 2189
终归单人心
终归单人心 2020-11-22 17:02

I\'m trying to find a short way to see if any of the following items is in a list, but my first attempt does not work. Besides writing a function to accomplish this, is the

14条回答
  •  一生所求
    2020-11-22 17:50

    Ah, Tobias you beat me to it. I was thinking of this slight variation on your solution:

    >>> a = [1,2,3,4]
    >>> b = [2,7]
    >>> any(x in a for x in b)
    True
    

提交回复
热议问题