[Tutor] Help with loops
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
[Tutor] HELP!!
So I am importing a csv file to textfile and the first column is product names and the second is a description of each. I am trying to find the sum of all descriptions using sum(c.values)). Here is my code so far: import csv import json import sys #from sys import argv from collections import defaultdict from collections import Counter #script, filename = argv data = defaultdict(list) counted_data = defaultdict(list) grouped_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]) #this appends the description(value) to the product name(key) #new_item = {} for key in data.keys(): #print key c = Counter(data[key]) for value in c: #print c[value] if c[value] >= 5: print key, ':', value, ':', c[value] elif c[value] <= 1: print 'other', ':', sum(c.values()) Please help!! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help!
Hi, So what I am working on is taking a csv file and only taking 2 columns from the spreadsheet and out putting that to a text file. Then taking those two columns and organize them by product(key) and outputting the description(values) that are associated. Some products have a lot of duplicate descriptions and I am trying to get the counts of those. I have a piece of code that takes anything greater then 5 and prints that and also anything 4 or less goes into an 'other' category with the counts.So what I am trying to do now is import a csv and change it to a text file with the same naming convention as the csv. Below is my functions code: import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self, filename): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.txt_output = " " def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict, def txt_output(self, filename): a = filename.split('.') self.txt_output = a + '.txt' print a def json_output(self): with open (self.txt_output.txt, 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) What I am having issues with is the def txt_output that is where I am trying to take the .csv off and add the .txt but keep the filename the same. For example, having a filename "weekly_20160102.csv" and then create a txt filename with "weekly_20160102.txt" and have all the counts and products in the text file. Is there any way to do this? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help!
Hi, So what I am working on is taking a csv file and only taking 2 columns from the spreadsheet and out putting that to a text file. Then taking those two columns and organize them by product(key) and outputting the description(values) that are associated. Some products have a lot of duplicate descriptions and I am trying to get the counts of those. I have a piece of code that takes anything greater then 5 and prints that and also anything 4 or less goes into an 'other' category with the counts.So what I am trying to do now is import a csv and change it to a text file with the same naming convention as the csv. Below is my functions code: import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self, filename): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.txt_output = " " def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict, def txt_output(self, filename): a = filename.split('.') self.txt_output = a + '.txt' print a def json_output(self): with open (self.txt_output.txt, 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) What I am having issues with is the def txt_output that is where I am trying to take the .csv off and add the .txt but keep the filename the same. For example, having a filename "weekly_20160102.csv" and then create a txt filename with "weekly_20160102.txt" and have all the counts and products in the text file. Is there any way to do this? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help!
Hi, I am trying to create a keyword search, so that someone can type in a key phrase and then the output be the value with the key. I have some code already done but having some trouble getting it to work. import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.keyword_dict = defaultdict(list) def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict def keyword_items(defaultdict, lookup): defaultdict = {' Tool Issue': ['Project Tool'], 'All catalogs missing or not updating': ['Design Tool']} for value, key in defaultdict.items(): for v in value: if lookup in v: return key def json_output(self): with open ('testing.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help!
Hi, I am working on a python script to automate reporting. And I am working on creating a keyword search. For example, if I want to search for the word Tool in the value and see what keys are associated with that. So say the value I have to search is Tool World and I want to know what key is associated with Tool World I search Tool World and it comes up with several results like missing or not updating and catalog issue. I have the basic code for it figured out but I have created my own dictionary for it called mydict and put a few key and values in but I want my code to search the csv file that I am importing and then take the info I am getting from the search results and put it in its own text file. I have attached my document. import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.search_dict = defaultdict(list) def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict mydict = {'Project Tool Issue': ['CPO Project Tool'], 'All catalogs missing or not updating': ['20/20 Design Tool']} def search(mydict, lookup): for key, value in mydict.iteritems(): for v in value: if lookup in v: #return key print key search(mydict, 'Tool') # def txt_output(self, filename): # a = filename.split('.') # self.txt_output = a + '.txt' # print a def json_output(self): with open ('testing.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] help!
Hi, I am working on a python script to automate reporting. And I am working on creating a keyword search. For example, if I want to search for the word Tool in the value and see what keys are associated with that. So say the value I have to search is Tool World and I want to know what key is associated with Tool World I search Tool World and it comes up with several results like missing or not updating and catalog issue. I have the basic code for it figured out but I have created my own dictionary for it called mydict and put a few key and values in but I want my code to search the csv file that I am importing and then take the info I am getting from the search results and put it in its own text file. Also, I dont want to have to create the mydict line with the keywords I want to be able to type in a value like Tool and search through the csv file and then output the results to a text file. I have attached my code. import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.search_dict = defaultdict(list) def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict mydict = {'Project Tool Issue': ['CPO Project Tool'], 'All catalogs missing or not updating': ['20/20 Design Tool']} def search(mydict, lookup): for key, value in mydict.iteritems(): for v in value: if lookup in v: #return key print key search(mydict, 'Tool') # def txt_output(self, filename): # a = filename.split('.') # self.txt_output = a + '.txt' # print a def json_output(self): with open ('scripttesting.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
Hi, I am working on a python script to automate reporting. And I am working on creating a keyword search. For example, if I want to search for the word Tool in the value and see what keys are associated with that. So say the value I have to search is Tool World and I want to know what key is associated with Tool World I search Tool World and it comes up with several results like missing or not updating and catalog issue. I have the basic code for it figured out but I have created my own dictionary for it called mydict and put a few key and values in but I want my code to search the csv file that I am importing and then take the info I am getting from the search results and put it in its own text file. Also, I dont want to have to create the mydict line with the keywords I want to be able to type in a value like Tool and search through the csv file and then output the results to a text file. So I guess what I want to do is take the row 2 and row 3 from the csv file and output that to text file then from there create a keyword search and output the results to another text file. import csv import json import sys from collections import defaultdict from collections import Counter class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.search_dict = defaultdict(list) mydict = defaultdict(list) def populate_dict(self, filename): with open (filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict #mydict = {'Project Tool Issue': ['CPO Project Tool'], 'All catalogs missing or not updating': ['20/20 Design Tool']} def search(mydict, lookup): for key, value in mydict.iteritems(): for v in value: if lookup in v: #return key print key search(mydict, 'Tool') # def txt_output(self, filename): # a = filename.split('.') # self.txt_output = a + '.txt' # print a def json_output(self): with open ('scripttesting.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with printing to text file
Hi, So I am trying to get my function search to print in a text file, but I can only get it to print to Powershell. I have tried several things to get it to print in its own text file but nothing I have tried is working. Can someone tell me what I am doing wrong? import csvimport sysimport jsonfrom collections import defaultdictfrom collections import Counter data = defaultdict(list) mydict = defaultdict(list) class dictionary: def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.search_dict = defaultdict(list) def populate_dict(self, filename): with open('weekly_test.csv', 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: str(total)}) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= 5: self.grouped_dict.update({value: key + ': ' + str(c[value])}) elif c[value] <= 4: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) self.final_dict = self.grouped_dict, self.other_dict, self.total_dict def json_output(self): with open ('weekly2.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) def search(self, filename): with open('weekly_test.csv', 'r') as searchfile: for line in searchfile: if 'PBI 43125' in line: print line with open('testdoc.txt', 'w') as text_file text_file = searchfile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with error
Hi, When I run my code I am getting an error it says "Attribute Error: Dictionary instance has no attribute 'search'. So the whole idea for my code is to input a csv file and output results that we want. This specific piece of code def search is to search the csv file for any keyword like 'issues' and output those results into a text file. I just need some help with figuring out how to fix the error I am receiving. This is my functions: import csvimport jsonimport sysfrom collections import defaultdictfrom collections import Counter data = defaultdict(list) upper_limit = 5 lower_limit = 4 class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) self.search_dict = defaultdict(list) def populate_dict(self, filename): with open(filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] new_list = str(total) #self.total_dict.update({key: 'Total count for this application: ' + str(total)}) #self.total_dict.update({key: str(total)}) self.total_dict[key].append(new_list) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= upper_limit: new_list = value, str(c[value]) self.grouped_dict[key].append(new_list) elif c[value] <= lower_limit: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) for d in (self.grouped_dict, self.other_dict, self.total_dict): for key, value in d.iteritems(): self.final_dict[key].append(value) def json_output(self): with open('test.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4) def search(self, filename): with open(filename, 'r') as searchfile, open('weekly_test.txt', 'w') as search_results_file: for line in searchfile: if 'PBI 43125' in line: print >>search_results_file, line And then I have another python file where I import my functions and run the results. Here is the code for that: import functions2 week_choice = raw_input("Previous Week or Current Week?")if week_choice == "current week": data = functions2.dictionary() filename = raw_input("What file do you want to use?") data.populate_dict(filename) data.total_counts() data.grouped_counts() data.json_output() data.search(filename) elif week_choice == "previous week": previous_data = functions2.dictionary() filename = raw_input("What file do you want to use?") previous_data.populate_dict(filename) previous_data.total_counts() previous_data.grouped_counts() previous_data.json_output() previous_data.search(filename) else: print "That choice is not correct" It says the error is with data.search(filename).. Not sure how to get this working. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] File extension change
Hi, So what I am working on is taking a csv file and only taking 2 columns from the spreadsheet and out putting that to a text file. Then taking those two columns and organize them by product(key) and outputting the description(values) that are associated. Some products have a lot of duplicate descriptions and I am trying to get the counts of those. I have a piece of code that takes anything greater then 5 and prints that and also anything 4 or less goes into an 'other' category with the counts.So what I am trying to do now is import a csv and change it to a text file with the same naming convention as the csv. But I want the text file to have the results from the json function. I want the text file that I am trying to output to have the same name as the filename I am importing. The file that I am inputting in the def populate_dict (usually the files are named weekly_and the date...ex: weekly_20160102.csv) and then i want to run all my code i have, but then in the def json_output instead of having the filename which i have now is 'test.txt' I want to have weekly_20160102.txt same naming convention as the csv file i am inputting. In my code I am soft coding the filename so that the user is prompted to enter what file they want to use. import csvimport jsonimport sysimport osfrom collections import defaultdictfrom collections import Counter upper_limit = 5 lower_limit = 4 class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.other_dict = defaultdict(list) self.final_dict = defaultdict(list) self.total_dict = defaultdict(list) def populate_dict(self, filename): with open(filename, 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: self.dict[row[2]].append(row[3]) with open(filename, 'r') as searchfile, open('weekly_test.txt', 'w') as search_results_file: for line in searchfile: if 'PBI 43125' in line: print >>search_results_file, line def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) def total_counts(self): for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] new_list = str(total) #self.total_dict.update({key: 'Total count for this application: ' + str(total)}) #self.total_dict.update({key: str(total)}) self.total_dict[key].append(new_list) def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) for value in c: if c[value] >= upper_limit: new_list = value, str(c[value]) self.grouped_dict[key].append(new_list) elif c[value] <= lower_limit: total += c[value] self.other_dict.update({key: 'other: ' + str(total)}) for d in (self.grouped_dict, self.other_dict, self.total_dict): for key, value in d.iteritems(): self.final_dict[key].append(value) def json_output(self): with open('test.txt', 'w') as text_file: json.dump(self.final_dict, text_file, sort_keys = True, indent = 4 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] date range
Hi, So I am taking in a csv file with several rows and one of those rows in a date row. I am trying to see if I can read in a csv file and search for a certain date range like 1/2/2016 to 1/5/2016. Something like that or a bigger date range. And then I want to ouput the results to either another csv or to a textfile. I am not sure how to even beginning this and was looking for some guidance on this. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with date range
So what I am trying to do is take in a csv file and the format of the csv file is: something, something1, something2,something3, something4, something5, something6, something7. Then in the csv file I want to search for a certain range of dates like 1/3/2016 - 2/3/2016. I can get individual dates but not a range of dates. I have an if elif statement to read row5 which is the date row. My if statement is the initial pass at returning the values within the date range and then my elif is the parameter and if there is no parameter passed in then it returns all data. I am having some trouble trying to pass in a date range parameter. The piece of code is under the def populate_dict function the date_choice part. Here is the code: import csvimport jsonimport sysimport osfrom collections import defaultdictfrom collections import Counter UPPER_LIMIT = 5 LOWER_LIMIT = 4 class dictionary(): def __init__(self): self.dict = defaultdict(list) self.counted_dict = defaultdict(list) self.grouped_dict = defaultdict(list) self.total_dict = defaultdict(list) def populate_dict(self, filename, date_choice, key_choice): with open(filename, 'rb') as f: reader = csv.reader(f) next(reader, None) # for row in reader: if date_choice == row[5]: self.dict[row[2]].append(row[3]) elif date_choice == "none": self.dict[row[2]].append(row[3]) if key_choice == row[3]: self.dict[row[2]].append(row[3]) elif key_choice == "none": self.dict[row[2]].append(row[3]) def all_counts(self): data_count = Counter() for key in self.dict.keys(): self.counted_dict.update({key: Counter(self.dict[key])}) # returns the total counts for each application def total_counts(self): self.total_dict.update({'Application': 'Incident Count'}) for key in self.dict.keys(): total = 0 b = Counter(self.dict[key]) for value in b: total += b[value] self.total_dict.update({key: total}) # returns the counts of incidents if they are greater than or equal to 5, and groups the rest in an "other" category def grouped_counts(self): for key in self.dict.keys(): total = 0 c = Counter(self.dict[key]) self.grouped_dict[key].append(['Description', 'Incident Count']) for value in c: if c[value] >= UPPER_LIMIT: grouped_list = value, c[value] self.grouped_dict[key].append(grouped_list) elif c[value] <= LOWER_LIMIT: total += c[value] other_list = "other ", total self.grouped_dict[key].append(other_list) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor