I need to create a loop to print out the most common phrases with the counts 5 or greater and the rest to be bucketed into other category. How do I write the loop to print out the common phrases that have counts of 5 or more? This is my code so far:
import csv#from sys import argvfrom collections import defaultdictfrom collections import Counter#script, filename = argv data = defaultdict(list) class dictionary: with open ('practice.csv', 'rb') as f: reader = csv.reader(f) #text_file = open("output.txt", "w") next(reader, None) for row in reader: data[row[2]].append(row[3]) #text_file.write("%r" % data) #text_file.close() #print(data) text_file = open("count.txt", "w") data_count = Counter() for d in data.values(): data_count += Counter(d) print data_count.most_common(5) text_file.write("%r" % data_count.most_common(5)) text_file.close() _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor