Hi, I'm new to programming so please excuse any obvious questions.
I have a text file with the following entries:
mydescription, myword
yellow, mango
yellow, banana
orange, orange
green, pineapple
green, mango
pink, mango
What's important is that there is no order, both the 'mydescription' field and 'myword' change randomly. I need to count the number of unique mydescriptions each myword appears with. So for example in the above lines mango appears with two unique colours - yellow and green so it would have a count of 2.
I'm trying to put them into a dictionary with the mywords as keys and mydescriptions as a list of values.
dict = {}
for line in file:
mydesc,myword = line.split(',')
if myword in dict:
dict[myword] = list.append(mydescription) //is this correct?
else:
dict[myword] = create a new list with first entry here..
I'm unable to put the above algorithm into Python syntax. How do I create a list as a value to the dict so it can be:
dict[myword] = [number of mynumbers associated with that word]
Thanks,
Mendo