From 5266fcea608d945b2741d501de0219977c73255f Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Mon, 6 Apr 2015 11:05:46 -0700 Subject: [PATCH] updated baby names code that it is works with python3 --- README | 8 ++++---- babynames1.py | 2 +- babynames2.py | 2 +- babynames3.py | 4 ++-- ssadata.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README b/README index 49e67de..4dcc615 100644 --- a/README +++ b/README @@ -1,12 +1,12 @@ -Copyright ⓒ 2014 Benjamin Mako Hill (http://mako.cc/) +Copyright ⓒ 2014-2015 Benjamin Mako Hill (http://mako.cc/) -Released as free software under the GNU General Public License v2 or any -later version. +Released as free software under the GNU General Public License v3 or any later +version. These are example programs for use in the Community Data Science Workshops. More details are available here: -https://openhatch.org/wiki/Community_Data_Science_Workshops +http://wiki.communitydata.cc/Community_Data_Science_Workshops Data for this project (the txt files) are downloaded from the US Social Security administration and are public domain: diff --git a/babynames1.py b/babynames1.py index 8111cf3..6070eee 100644 --- a/babynames1.py +++ b/babynames1.py @@ -2,5 +2,5 @@ import ssadata for name in ssadata.boys.keys(): if name == "mako": - print "There were " + str(ssadata.boys[name]) + " boys named " + name + print("There were " + str(ssadata.boys[name]) + " boys named " + name) diff --git a/babynames2.py b/babynames2.py index 752b4f5..075cb27 100644 --- a/babynames2.py +++ b/babynames2.py @@ -2,4 +2,4 @@ import ssadata for name in ssadata.boys.keys(): if name in ssadata.girls.keys(): - print name + print(name) diff --git a/babynames3.py b/babynames3.py index d393234..f83e0e8 100644 --- a/babynames3.py +++ b/babynames3.py @@ -2,8 +2,8 @@ import ssadata for name in ssadata.boys.keys(): if 'king' in name: - print name + " " + str(ssadata.boys[name]) + print(name + " " + str(ssadata.boys[name])) for name in ssadata.girls.keys(): if 'queen' in name: - print name + " " + str(ssadata.girls[name]) + print(name + " " + str(ssadata.girls[name])) diff --git a/ssadata.py b/ssadata.py index dc217e7..96055a3 100644 --- a/ssadata.py +++ b/ssadata.py @@ -3,7 +3,7 @@ NAMES_LIST = "yob2013.txt" boys = {} girls = {} -for line in file(NAMES_LIST, 'r').readlines(): +for line in open(NAMES_LIST, 'r').readlines(): name, gender, count = line.strip().split(",") count = int(count) -- 2.39.5