-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path02_ice_cream_machine.py
More file actions
42 lines (28 loc) · 1.23 KB
/
02_ice_cream_machine.py
File metadata and controls
42 lines (28 loc) · 1.23 KB
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
"""
10 min
Implement the IceCreamMachine's scoops method so that it returns all
combinations of one ingredient and one topping. If there are no ingredients or
toppings, the method should return an empty list.
For example,
IceCreamMachine(["vanilla", "chocolate"], ["chocolate sauce"]).scoops()
should return
[['vanilla', 'chocolate sauce'], ['chocolate', 'chocolate sauce']].
class IceCreamMachine:
def __init__(self, ingredients, toppings):
self.ingredients = ingredients
self.toppings = toppings
def scoops(self):
pass
machine = IceCreamMachine(["vanilla", "chocolate"], ["chocolate sauce"])
print(machine.scoops()) #should print[['vanilla', 'chocolate sauce'], ['chocolate', 'chocolate sauce']]
"""
from itertools import product
class IceCreamMachine:
def __init__(self, ingredients, toppings):
self.ingredients = ingredients
self.toppings = toppings
def scoops(self):
return [list(p) for p in product(self.ingredients, self.toppings)]
if __name__ == "__main__":
machine = IceCreamMachine(["vanilla", "chocolate"], ["chocolate sauce"])
print(machine.scoops()) #should print[['vanilla', 'chocolate sauce'], ['chocolate', 'chocolate sauce']]