From 8b9893cdc0a2ea5c693e6362b7f7f7187f70fe4f Mon Sep 17 00:00:00 2001 From: Aditya Bhargava Date: Wed, 2 Mar 2016 14:32:36 -0800 Subject: [PATCH] code for chapter 5 --- 05_hash_tables/python/01_price_of_groceries.py | 7 +++++++ 05_hash_tables/python/02_check_voter.py | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 05_hash_tables/python/01_price_of_groceries.py create mode 100644 05_hash_tables/python/02_check_voter.py diff --git a/05_hash_tables/python/01_price_of_groceries.py b/05_hash_tables/python/01_price_of_groceries.py new file mode 100644 index 0000000..6eeddb4 --- /dev/null +++ b/05_hash_tables/python/01_price_of_groceries.py @@ -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 diff --git a/05_hash_tables/python/02_check_voter.py b/05_hash_tables/python/02_check_voter.py new file mode 100644 index 0000000..0b2cb02 --- /dev/null +++ b/05_hash_tables/python/02_check_voter.py @@ -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")