Python 在列表列表中找到特定列表的次数

Python 在列表列表中找到特定列表的次数,python,python-3.x,list,list-comparison,Python,Python 3.x,List,List Comparison,我有以下清单 a = ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges'] 以及下面的列表 b = [['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges'], ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges', 'Pear', 'Apple'], ['Oranges', 'Strawberry', 'Pear'], ... ] 如您所见,在b的

我有以下清单

a = ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges']
以及下面的列表

b = [['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges'], ['Bananas', 'Ananas', 'Peach', 'Grapes', 'Oranges', 'Pear', 'Apple'], ['Oranges', 'Strawberry', 'Pear'], ... ]
如您所见,在b的内部有可能

  • A
  • A项目相同但顺序不同的列表
  • 与1和2相似,但项目多于a
  • 与1和2相似,但项目少于a
  • A
  • 考虑到使用

    for value in b:
        print(value)
    
    我们可以得到每个b列表,然后将其与a进行比较,如何知道案例1、2和3发生了多少次(包括重复)


    受到启发,我进行了实验

    count_matches = 0
    
    for value in b:
        ff = str(value).strip("[]")
        gg = str(a).strip("[]")
        if gg in ff:
            count_matches += 1
    
    print(count_matches)
    

    但是,由于顺序的原因,这不起作用(例如,其他项目可以添加到中间)。

    为了解决这个问题,我结合for循环来获得值,如中所示

    count_matches = 0
    for value in b:
        if set(a) <= set(value):
            count_matches += 1
            print("a is in b")  
    
    count\u匹配=0
    对于b中的值:
    如果设置了(a)