I have a list of words given below (example):
['the', 'counter', 'starts', 'the', 'starts', 'for']
I want to process this list in order and generate a pair (x,y)
where x is incremented with each word and y is incremented only when it sees a unique word.
So for the given example, my output should be like:[(1,1) (2,2), (3,3) (4,3) (5,3) (6,4)]
I am not sure about how to do this in python. It would be great if i can get some insights on how to do this. Thanks.
try this:
>>>from collections import Counter
>>>data = ['the', 'counter', 'starts', 'the', 'starts', 'for']
>>>tally=Counter()
>>>for elem in data:
>>> tally[elem] += 1
>>>tally
Counter({'starts': 2, 'the': 2, 'counter': 1, 'for': 1})
from here: http://docs.python.org/2/library/collections.html
Of course, this results in a dictionary not a list. I wouldn't know if there's any way to convert this dict to a list (like some zip function ?) Hope it might be any help for anyone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With