Last active
August 29, 2015 14:23
-
-
Save Sanjogsharma/4d62027e6f609e90e2cc to your computer and use it in GitHub Desktop.
Homework For Class 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| PART 1: | |
| ''' | |
| import csv | |
| from collections import defaultdict | |
| chicken = list(csv.reader(open('chipotle.tsv', 'rb'), delimiter='\t')) | |
| #type(chicken) gives a list | |
| ''' | |
| PART 2: | |
| ''' | |
| orders_headers = chicken[0] | |
| orders = chicken[1:] | |
| ''' | |
| PART 3: | |
| ''' | |
| list_orders = [float(order[-1][1:]) for order in orders] #quantity not important b/c price is quantity*cost | |
| average_orders = (sum(list_orders))/(len(list_orders)) #7.46 | |
| ''' | |
| PART 4: | |
| ''' | |
| drinks_all = [] | |
| for drinks in orders: | |
| if drinks[2] == 'Canned Soft Drink' or drinks[2] == 'Canned Soda': | |
| drinks_all.append(drinks[3]) | |
| #couldn't get this to work as list comprehension :( | |
| drinks_set = [unique for unique in set(drinks_all)] | |
| #it's a list of list, I tried to create a list with strings without success | |
| #set(drinks_all) creates a set | |
| ''' | |
| PART 5: | |
| ''' | |
| # Alex: use number of commas in the choice column to figure | |
| # out the number of toppings. | |
| burrito_topping = [] | |
| for item in orders: | |
| if item[2].endswith('Burrito'): | |
| burrito_topping.append((len(str(item[3]).split(',')) + 1)) | |
| average_topping = float(sum(burrito_topping))/float(len(burrito_topping) ) | |
| #6.39 | |
| ''' | |
| PART 6: | |
| ''' | |
| chips_dictionary = {'Chips and Roasted Chili-Corn Salsa':0, | |
| 'Chips and Tomatillo-Red Chili Salsa':0, | |
| 'Chips and Mild Fresh Tomato Salsa':0, | |
| 'Chips and Guacamole':0, | |
| 'Chips and Fresh Tomato Salsa':0, | |
| 'Chips and Tomatillo-Green Chili Salsa':0, | |
| 'Chips and Tomatillo Red Chili Salsa':0, | |
| 'Chips and Roasted Chili Corn Salsa':0, | |
| 'Chips':0, | |
| 'Chips and Tomatillo Green Chili Salsa':0 | |
| } | |
| for chips in orders: | |
| if chips[2].startswith('Chips'): #valid | |
| chips_dictionary[chips[2]] += int(chips[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment