-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecipe_recommender.py
76 lines (67 loc) · 2.28 KB
/
recipe_recommender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
__author__ = 'Emma Grasmeder'
"@emma_gras" # Twitter
# For the Mother-Daughter Hackathon (30 minutes)
# Note: Written for Python 3,
# Use screenshots beneath ## Slide X ## header
## Slide 1 ##
## Basic Data Structures:
#examples of integers:
1
2
33
-99999
## Slide 2 ##
# examples of strings:
"cat"
"house"
"36"
"[ ]"
"one"
## Slide 3 ##
# examples of variables
x = 13
var1 = "these few w0rds"
## Slide 4 ##
# examples of lists:
word_list = ["cat", "dog", "house"]
int_list = [1, 2, 3, 4]
list_of_lists = [[1, 2, 3],
["a", "b", "c"],
[]]
## Slide 5 ##
# examples of dictionaries:
word_dictionary = {"housecat": "a small mammal that says 'meow' ",
"dog": "a human's best friend",
"house": "a common habitat for humans to dwell"}
int_to_string_dict = {1: ["one", "1"],
2: ["two", "2"],
303: ["three hundred three", "303"]}
## Slide 6 ##
## A Minimum Viable Cook Book!
# Dishes are stored in the format: ["dish name",
# "ingredient 1",..."ingredient n"]
# for all n in the required ingredients
boiled_egg = ["boiled egg","egg"]
scrambled_egg = ["scrambled egg", "egg"]
french_bread = ["french bread", "flour", "yeast", "salt", "water"]
recipes = [boiled_egg, scrambled_egg, french_bread]
## Slide 7 ##
what_we_have = [] # this is an empty list that will be filled with user input
while True:
response = str(input("enter ingredients you have, then type 'done' when finished: "))
if response != "done":
what_we_have.append(response)
else:
break
## Slide 8 ##
for r in recipes: # here we're iterating through all the recipes
# The first item in r is the name of the dish, so ignore it
ingredients = r[1:] # we ignore the first item by slicing
if set(ingredients).issubset(set(what_we_have)): # see note below
print("You can cook {}!".format(r[0]))
# note about "set(a).issubset(set(b))":
# Think about venn diagrams when thinking about subsets.
# [1,2,3] is a subset of [5,4,3,2,1] because every item in
# the list [1,2,3] is also in [5,4,3,2,1].
# If we have 5 products and the recipe only requires 3 out of that
# the 5, we can be certain we can make the recipe.