I am trying to compare y with x, such that it will return the amount of matches and it strictly follows the value of y.
For example, in this scenario, it should return a count of 2 as there are 2 matches of ['a', 'b'].
x = ['a', 'b'], ['b', 'c'], ['d', 'c'], ['a', 'b']
y = ['a', 'b']
CodePudding user response:
Use the list 'count' method.
x = [['a', 'b'], ['b', 'c'], ['d', 'c'], ['a', 'b']]
y = ['a', 'b']
my_count = x.count(y) # 2
CodePudding user response:
If I understand what you want, the result will be 2, so you have to iterate through the x list and for each value compare it with y, right?
x = [['a', 'b'], ['b', 'c'], ['d', 'c'], ['a', 'b']]
y = ['a', 'b']
sum = 0
for i in x:
if i == y:
sum =1
print(sum)