I have a two list as follows
x = ['a','a','b','c','b','a']
and
x = ['a','a','b','c','c','d']
I'm trying to find which values occur the most in each of these lists. This is what I have tried.
def unique_values(output,input):
for i in input:
if i not in output:
output.append(i)
k = []
for i in k:
unique_values(k,x)
y.remove(i)
I've gotten this far but I cant figure out how to stop the for i in k: before it removes all the values in the list.
解决方案
You can use Counter module from collections, if you want to find the occurrences of each element in the list: -
>>> x = ['a','a','b','c','