On 12/01/16 20:36, Chelsea G wrote: > data = defaultdict(list) > > class dictionary: > with open ('weekly_20160102.csv', 'rb') as f: > reader = csv.reader(f) > next(reader, None) > for row in reader: > data[row[2]].append(row[3]) > for key in data.keys(): > c = Counter(data[key]) > for value in c: > if c[value] >= 5: > print key, ':', value, ':', c[value] > elif c[value] <= 1: > print 'other', ':', sum(c.values())
I think that's what your code was supposed to look like. Am I right? If so you have all the code inside a class definition. But you do nothing with the class and it certainly doesn't define a dictionary. Its not clear what the class line is for. That aside, This implies the data format has 4 columns and you are throwing away the first two and using the third as a key to find the fourth. Is that correct? It's certainly not what your introductory paragraph said. But I don't understand what you think the Counter is doing? You are counting how many there are of each key, but a dict can only have unique keys so it must always be 1. Then you iterate over the Counter and none of that makes any sense. I can't even think what you are trying to do. Can you confirm the code layout - ideally by posting a plain text version. And explain how you think it is supposed to work. Also please show us a sample (3-10 lines) of input data and what exactly you expect the output to be. Thanks, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor