code for chapter 5
This commit is contained in:
7
05_hash_tables/python/01_price_of_groceries.py
Normal file
7
05_hash_tables/python/01_price_of_groceries.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
book = dict()
|
||||||
|
# an apple costs 67 cents
|
||||||
|
book["apple"] = 0.67
|
||||||
|
# milk costs $1.49
|
||||||
|
book["milk"] = 1.49
|
||||||
|
book["avocado"] = 1.49
|
||||||
|
print book
|
||||||
11
05_hash_tables/python/02_check_voter.py
Normal file
11
05_hash_tables/python/02_check_voter.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
voted = {}
|
||||||
|
def check_voter(name):
|
||||||
|
if voted.get(name):
|
||||||
|
print "kick them out!"
|
||||||
|
else:
|
||||||
|
voted[name] = True
|
||||||
|
print "let them vote!"
|
||||||
|
|
||||||
|
check_voter("tom")
|
||||||
|
check_voter("mike")
|
||||||
|
check_voter("mike")
|
||||||
Reference in New Issue
Block a user