I have a list in my hand and I want to create vocabulary from this list. Then, I want to show each word and count the same strings in this list.
The sample list as below.
new_list = ['one', 'thus', 'once', 'one', 'count', 'once', 'this', 'thus']
First, I created a vocabulary with below.
vocabulary = []
for i in range (0, len(new_list)):
if new_list[i] not in vocabulary:
vocabulary.append(new_list[i])`
print vocabulary
The output of above code is: "count, once, one, this, thus."
I want to show the number of each words in the list as below. [count][1], [once][2], [one][2], [this][1], [thus][2].
In order to get above result; I try below code.
matris = []
for i in range(0,len(new_list)):
temp = []
temp.insert(0,new_list.count(new_list[i]))
matris.append(temp)
for x in matris:
print x
Above code only gives the number of words. Can someone advise me how can I print the word name and number of the words together such as in [once][2] format.