How to check a list contained by another list without a loop?

前端 未结 4 1786
攒了一身酷
攒了一身酷 2020-12-31 01:33

As the title mentions,is there any builtins to do this job?I looked for that in dir(list) but got no usable one.Thanks.

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 01:47

    Depends on what you mean by "contained". Maybe this:

    if set(a) <= set(b):
        print "a is in b"
    

提交回复
热议问题