├── DANDANDAN.py ├── DiveIntoPython └── FileInfo.py ├── Dummies ├── book_spider.py ├── spider.py └── spider.pyc ├── LearningPython ├── __pycache__ │ ├── myfile.cpython-32.pyc │ ├── script1.cpython-32.pyc │ ├── threenames.cpython-32.pyc │ └── threenames2.cpython-32.pyc ├── import_3.py ├── myfile.py ├── script1.py ├── script1.pyc ├── threenames.py └── threenames2.py ├── ListTuple.py ├── OOP └── myclass.py ├── README.md ├── TheHardWay ├── download-learn-python-the-hard-way-2nd-edition.pdf ├── ex1.py ├── ex10.py ├── ex11.py ├── ex12.py ├── ex13.py ├── ex2.py ├── ex3.py ├── ex4.py ├── ex5.py ├── ex6.py ├── ex7.py ├── ex8.py ├── ex9.py ├── format_strings.py ├── fun.py ├── funky.py ├── input.py ├── printing.py ├── tabs.py └── test1.py ├── TheNewBoston ├── add.py └── ifelse ├── array.py ├── array.pyc ├── bar ├── branch1 ├── branch2 ├── branch3 ├── buildconstring.py ├── buildconstring.pyc ├── chkdirs.py ├── chkps.py ├── chkurl.py ├── chkurl.py.socket ├── class.py ├── class2.py ├── cmds.py ├── countdown.py ├── counter.py ├── doc_string.py ├── esent_ref ├── Behave.py └── beehive.py ├── findit.py ├── foo ├── foo.py ├── foo1.py ├── foo2.py ├── for.py ├── freestyle └── prac1.py ├── git_notes.txt ├── google-python-exercises ├── LICENSE.txt ├── NOTICE.txt ├── babynames │ ├── baby1990.html │ ├── baby1992.html │ ├── baby1994.html │ ├── baby1996.html │ ├── baby1998.html │ ├── baby2000.html │ ├── baby2002.html │ ├── baby2004.html │ ├── baby2006.html │ ├── baby2008.html │ ├── babynames.py │ └── solution │ │ └── babynames.py ├── basic │ ├── alice.txt │ ├── list1.py │ ├── list2.py │ ├── mimic.py │ ├── small.txt │ ├── solution │ │ ├── list1.py │ │ ├── list2.py │ │ ├── mimic.py │ │ ├── string1.py │ │ ├── string2.py │ │ └── wordcount.py │ ├── string1.py │ ├── string2.py │ └── wordcount.py ├── copyspecial │ ├── copyspecial.py │ ├── solution │ │ └── copyspecial.py │ ├── xyz__hello__.txt │ └── zz__something__.jpg ├── hello.py ├── hello.pyc └── logpuzzle │ ├── animal_code.google.com │ ├── logpuzzle.py │ ├── place_code.google.com │ └── solution │ └── logpuzzle.py ├── gui.py ├── gui2.py ├── ifelse.py ├── import.py ├── isfile.py ├── large_re_file.txt ├── log.py ├── makepass.py ├── makepass.pyc ├── module.py ├── my_new_module ├── my_restore.py ├── new_pysysinfo.py ├── nfl_team_pick.py ├── openfile.py ├── prac.py ├── pyls.py ├── pysysinfo.py ├── rib ├── socket.py ├── socket.pyc ├── test_func.py ├── test_func2.py ├── testssh.py ├── tryex1.py ├── tutorial.py └── url_check.py /DANDANDAN.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os,sys 4 | 5 | passwd="/etc/passwd" 6 | if not os.path.isfile(passwd): 7 | print "Can't open %s." % passwd 8 | sys.exit(1) 9 | 10 | 11 | format="%-18s %-17s %10s %-9s" 12 | print format % ("", "", "Disk ", "") 13 | print format % ("Username (UID)", "Home Directory", 14 | "Space", "Security") 15 | print "---------------------------------------------\ 16 | ---------------" 17 | for line in open(passwd).readlines(): 18 | (uname, xpass, uid, gid, junk, home_dir, junk2) = line.split(':') 19 | if uname == 'root' or uname == 'nobody' or uname[0:2] == 'uu': 20 | continue 21 | uid = int(uid) 22 | if uid <= 100 and uid > 0: 23 | continue 24 | if uid == 0 and uname != 'root': 25 | warn = "** UID=0" 26 | elif xpass != '!' and xpass != '*' and xpass != 'x': 27 | warn = "** CK PASS" 28 | else: 29 | warn = "" 30 | if os.path.isdir(home_dir) and home_dir != '/': 31 | disk = os.popen("du -s -k %s 2>/dev/null" % 32 | home_dir).read().split('\t')[0] 33 | if disk == '': 34 | disk = "unknown" 35 | else: 36 | disk += "K" 37 | else: 38 | disk = "skipped" 39 | print format % ("%s (%s)" % (uname, uid), home_dir, \ 40 | disk, warn) 41 | 42 | ''' 43 | doc 44 | ''' 45 | -------------------------------------------------------------------------------- /DiveIntoPython/FileInfo.py: -------------------------------------------------------------------------------- 1 | class FileInfo(UserDice): 2 | "store file metadata" 3 | def __init__(self, filename=None): 4 | UserDict.__init__(self) 5 | self["name"] = filename 6 | -------------------------------------------------------------------------------- /Dummies/book_spider.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################### 4 | # program: spider.py 5 | # author: aahz 6 | # version: 1.1 7 | # date: June 2006 8 | # description: start on command line with URL argument. 9 | # Finds pages within a web site. 10 | ############################################### 11 | 12 | # These modules do most of the work. 13 | import sys 14 | import urllib2 15 | import urlparse 16 | import htmllib, formatter 17 | from cStringIO import StringIO 18 | 19 | 20 | def log_stdout(msg): 21 | """Print msg to the screen.""" 22 | print msg 23 | 24 | def get_page(url, log): 25 | """Retrieve URL and return contents, log errors.""" 26 | try: 27 | page = urllib2.urlopen(url) 28 | except urllib2.URLError: 29 | log("Error retrieving: " + url) 30 | return '' 31 | body = page.read() 32 | page.close() 33 | return body 34 | 35 | def find_links(html): 36 | """Return a list of links in html.""" 37 | # We're using the parser just to get the HREFs 38 | writer = formatter.DumbWriter(StringIO()) 39 | f = formatter.AbstractFormatter(writer) 40 | parser = htmllib.HTMLParser(f) 41 | parser.feed(html) 42 | parser.close() 43 | return parser.anchorlist 44 | 45 | 46 | class Spider: 47 | 48 | """ 49 | The heart of this program, finds all links within a web site. 50 | 51 | run() contains the main loop. 52 | process_page() retrieves each page and finds the links. 53 | """ 54 | 55 | def __init__(self, startURL, log=None): 56 | # This method sets initial values 57 | self.URLs = set() 58 | self.URLs.add(startURL) 59 | self.include = startURL 60 | self._links_to_process = [startURL] 61 | if log is None: 62 | # Use log_stdout function if no log provided 63 | self.log = log_stdout 64 | else: 65 | self.log = log 66 | 67 | def run(self): 68 | # Processes list of URLs one at a time 69 | while self._links_to_process: 70 | url = self._links_to_process.pop() 71 | self.log("Retrieving: " + url) 72 | self.process_page(url) 73 | 74 | def url_in_site(self, link): 75 | # Checks whether the link starts with the base URL 76 | return link.startswith(self.include) 77 | 78 | def process_page(self, url): 79 | # Retrieves page and finds links in it 80 | html = get_page(url, self.log) 81 | for link in find_links(html): 82 | # Handle relative links 83 | link = urlparse.urljoin(url, link) 84 | self.log("Checking: " + link) 85 | # Make sure this is a new URL within current site 86 | if link not in self.URLs and self.url_in_site(link): 87 | self.URLs.add(link) 88 | self._links_to_process.append(link) 89 | 90 | 91 | if __name__ == '__main__': 92 | # This code runs when script is started from command line 93 | startURL = sys.argv[1] 94 | spider = Spider(startURL) 95 | spider.run() 96 | for URL in sorted(spider.URLs): 97 | print URL 98 | -------------------------------------------------------------------------------- /Dummies/spider.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ############################## 4 | # program: spider.py 5 | # author: aahz 6 | # version: 1.1 7 | # date: Feb 7 2012 8 | # description: start on commandline with URL argument. 9 | # Finds pages within a web site. 10 | ############################## 11 | 12 | # These modules do most of the work 13 | import sys 14 | import urllib2 15 | import urlparse 16 | import htmllib, formatter 17 | from cStringIO import StringIO 18 | 19 | 20 | def log_stdout (msg): 21 | """Print msg to the screen.""" 22 | print msg 23 | 24 | 25 | def get_page(url, log): 26 | """Retrieve URL and return contents, log errors.""" 27 | try: 28 | page = urllib2.urlopen(url) 29 | except urllib2.URLError: 30 | log("Error retrieving: " + url) 31 | return '' 32 | body = page.read() 33 | page.close() 34 | return body 35 | 36 | 37 | def find_links(html): 38 | """Return a list of links in html.""" 39 | # We're using the parser just to get the HREFs 40 | writer = formatter.DumbWriter(StringIO()) 41 | f = formatter.AbstractFormatter(writer) 42 | parser = htmllib.HTMLParser(f) 43 | parser.feed(html) 44 | parser.close() 45 | return parser.anchorlist 46 | 47 | 48 | class Spider: 49 | 50 | """ 51 | The heart of this program, finds all links within a web site. 52 | 53 | run() contains the main loop. 54 | process_page() retrieves each page and finds the links. 55 | """ 56 | 57 | 58 | def __init__(self, startURL, log=None): 59 | # This method sets initial values 60 | self.URLs = set() 61 | self.URLs.add(startURL) 62 | self.include = startURL 63 | self._links_to_process = [startURL] 64 | if log is None: 65 | # Use log_stdout function if no log provided 66 | self.log = log_stdout 67 | else: 68 | self.log = log 69 | 70 | 71 | def run(self): 72 | # Processes list of URLs one at a time 73 | while self._links_to_process: 74 | url = self._links_to_process.pop() 75 | self.log("Retrieving: " + url) 76 | self.process_page(url) 77 | 78 | 79 | def url_in_site(self, link): 80 | # Checks whether the link starts with the base URL 81 | return link.startswith(self.include) 82 | 83 | 84 | def process_page(self, url): 85 | # Retrieves page and finds links in it 86 | html = get_page(url, self.log) 87 | for link in find_links(html): 88 | # Handle relative links 89 | link = urlparse.urljoin(url, link) 90 | self.log("Checking: " + link) 91 | # Make sure this is a new URL within current site 92 | if link not in self.URLs and self.url_in_site(link): 93 | self.URLs.add(link) 94 | self._links_to_process.append(link) 95 | 96 | 97 | if __name__ == '__main__': 98 | # This code runs when script is started from command line 99 | startURL = sys.argv[1] 100 | spider = Spider(startURL) 101 | spider.run() 102 | for URL in sorted(spider.URLs): 103 | print URL 104 | -------------------------------------------------------------------------------- /Dummies/spider.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/Dummies/spider.pyc -------------------------------------------------------------------------------- /LearningPython/__pycache__/myfile.cpython-32.pyc: -------------------------------------------------------------------------------- 1 | l 2 | ]L~Mc@s 3 | dZdS(uThe Meaning of LifeN(utitle(((u myfile.pyus -------------------------------------------------------------------------------- /LearningPython/__pycache__/script1.cpython-32.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/LearningPython/__pycache__/script1.cpython-32.pyc -------------------------------------------------------------------------------- /LearningPython/__pycache__/threenames.cpython-32.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/LearningPython/__pycache__/threenames.cpython-32.pyc -------------------------------------------------------------------------------- /LearningPython/__pycache__/threenames2.cpython-32.pyc: -------------------------------------------------------------------------------- 1 | l 2 | om~Mc@sdZdZdZdS(ustarlingublackulotN(uaubuc(((uthreenames2.pyus -------------------------------------------------------------------------------- /LearningPython/import_3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import script1 4 | from imp import reload 5 | import imp 6 | imp.reload(script1) 7 | 8 | 9 | import myfile 10 | t = myfile.title 11 | print (t) 12 | 13 | from myfile import title 14 | print (title) 15 | -------------------------------------------------------------------------------- /LearningPython/myfile.py: -------------------------------------------------------------------------------- 1 | title = "The Meaning of Life" 2 | -------------------------------------------------------------------------------- /LearningPython/script1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # A first Python script 4 | 5 | if __name__ == '__main__': 6 | import sys 7 | print(sys.platform) 8 | print(2 ** 100) 9 | x = 'Spam!' 10 | print(x * 8) 11 | #input() 12 | 13 | -------------------------------------------------------------------------------- /LearningPython/script1.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/LearningPython/script1.pyc -------------------------------------------------------------------------------- /LearningPython/threenames.py: -------------------------------------------------------------------------------- 1 | a = 'dead' 2 | b = 'parrot' 3 | c = 'sketch' 4 | 5 | print(a, b, c) 6 | -------------------------------------------------------------------------------- /LearningPython/threenames2.py: -------------------------------------------------------------------------------- 1 | a = 'starling' 2 | b = 'black' 3 | c = 'lot' 4 | -------------------------------------------------------------------------------- /ListTuple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | aList = [1, 2, 3, 4] 4 | print aList 5 | 6 | print aList[0] 7 | 8 | print aList[:3] 9 | 10 | print aList[2:] 11 | 12 | print aList[:3] 13 | 14 | aList[1] = 5 15 | 16 | print aList 17 | 18 | 19 | aTuple = ('robots', 77, 93, 'try') 20 | 21 | print aTuple 22 | 23 | print aTuple [:3] 24 | 25 | 26 | -------------------------------------------------------------------------------- /OOP/myclass.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | class myClass: 5 | name = "Dan" 6 | eyes = "blue" 7 | height = 54 8 | weight = 165 9 | age = 34 10 | birth = 040277 11 | 12 | def myMethod 13 | print "Hi %s", % (name) 14 | 15 | me = myClass 16 | 17 | print me.eyes 18 | print me.age 19 | print me.weight 20 | print me.birth 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/README.md -------------------------------------------------------------------------------- /TheHardWay/download-learn-python-the-hard-way-2nd-edition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/TheHardWay/download-learn-python-the-hard-way-2nd-edition.pdf -------------------------------------------------------------------------------- /TheHardWay/ex1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # ex1.py 5 | # printing 6 | # 7 | 8 | print "Hello World!" 9 | print "Hello Again" 10 | print "I like typing this" 11 | print "This is fun." 12 | print "Yay! Printing" 13 | print "I'd much rather you 'not" 14 | print 'I "said" do not touch this.' 15 | -------------------------------------------------------------------------------- /TheHardWay/ex10.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | tabby_cat = "\tI'm tabbed in." 5 | persian_cat = "I'm split\n 6 | -------------------------------------------------------------------------------- /TheHardWay/ex11.py: -------------------------------------------------------------------------------- 1 | print "How old are you?", 2 | age = raw_input() 3 | print "How tall are you?" 4 | height = raw_input() 5 | print "How much do you weigh?", 6 | weight = raw_input() 7 | 8 | print "So, you're %r old, %r tall and %r heavy" % ( 9 | age, height, weight) 10 | -------------------------------------------------------------------------------- /TheHardWay/ex12.py: -------------------------------------------------------------------------------- 1 | age = raw_input("How old are you?") 2 | height = raw_input("How tall are you?") 3 | weight = raw_input("How much do you weight?") 4 | 5 | print "So you're %s old, %s tall and %s heavy." % ( 6 | age, height, weight ) 7 | -------------------------------------------------------------------------------- /TheHardWay/ex13.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from sys import argv 4 | 5 | script, first, second, third = argv 6 | 7 | print "The script is called:", script 8 | print "Your first variable is:", first 9 | print "Your second variable is:", first 10 | print "Your third variable is:", first 11 | -------------------------------------------------------------------------------- /TheHardWay/ex2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # ex2.py 5 | # 6 | # more printing strings 7 | # 8 | 9 | # A comment, this is so you can read your program later. 10 | # Anything after the # is ignored by python. 11 | 12 | print "I could have coded like this." # and the comment is ignored 13 | 14 | # You can also use a comment to "disabe" or comment out a piece of code 15 | # print "This won't run." 16 | print "This will run." 17 | -------------------------------------------------------------------------------- /TheHardWay/ex3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # ex3.py 4 | # 5 | # Practice a bit of math and expressions 6 | # 7 | 8 | print "I will now count my chickens:" 9 | 10 | print "Hens", 25 + 30 / 6 11 | print "Roosters", 100 - 25 * 3 % 4 12 | 13 | print "Now I will count the eggs:" 14 | 15 | print 3 + 2 +1 - 5 + 4 % 2 - 1 / 4 + 5 16 | 17 | print "It is true that 3 + 2 < 5 - 7?" 18 | 19 | print "What is 3 + 2?", 3 + 2 20 | print "What is 5 -7?", 5 - 7 21 | 22 | print "Oh, that's why its False." 23 | 24 | print "How about some more." 25 | 26 | print "Is it greater?", 5 > -2 27 | print "Is it greater or equal?", 5 >= 2 28 | -------------------------------------------------------------------------------- /TheHardWay/ex4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # ex4.py 5 | # 6 | # names and variables 7 | # 8 | 9 | cars = 100 10 | space_in_a_car = 4.0 11 | drivers = 30 12 | passengers = 90 13 | cars_not_driven = cars - drivers 14 | cars_driven = drivers 15 | carpool_capacity = cars_driven * space_in_a_car 16 | average_passengers_per_car = passengers / cars_driven 17 | 18 | print "There are", cars, "cars available." 19 | print "There are only", drivers, "drivers available." 20 | print "There will be", cars_not_driven, "empty cars today." 21 | print "We can transport", carpool_capactiy, "people today." 22 | print "We have", passengers, "to carpool today." 23 | print "We need to put about", average_passengers_per_car, "in each car." 24 | -------------------------------------------------------------------------------- /TheHardWay/ex5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | name = 'Dan L. Barnes' 4 | age = 35 # not a lie 5 | height = 74 # in inches 6 | weight = 165 # lbs 7 | eyes = 'Blue' 8 | teeth = 'White' 9 | hair = 'Brown' 10 | 11 | print "Let's talk about %s." % name 12 | print "He's %d inches tall." % height 13 | print "He's %d pounds havy" % weight 14 | print "Actually that's not too heavy." 15 | print "He's got %s eyes and %s hair." % (eyes, hair) 16 | print "His teeth are usually %s depending on the coffee." % teeth 17 | 18 | # this line is tricky, try to get it exactly right 19 | print "If I add %d, %d and %d I get %d." % ( 20 | age, height, weight, age + height + weight) 21 | -------------------------------------------------------------------------------- /TheHardWay/ex6.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # ex6.py 4 | 5 | x = "There are %d types of people." % 10 6 | binary = "binary" 7 | do_not = "dont't" 8 | y = "Those who know %s and those %s." % (binary, do_not) 9 | 10 | 11 | print x 12 | print y 13 | 14 | print "I said: %r." % x 15 | print "I also said: '%s'." % y 16 | 17 | hilarious = False 18 | joke_evaluation = "Isn't that joke so funny?! %r" 19 | 20 | print joke_evaluation % hilarious 21 | 22 | w = "This is the left side of..." 23 | e = "a string with a right side." 24 | 25 | print w + e 26 | -------------------------------------------------------------------------------- /TheHardWay/ex7.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # ex7 4 | 5 | print "Mary had a little lamb." 6 | print "Its fleece was white as %s." % 'snow' 7 | print "And everywhere that Mary went." 8 | print "." * 10 # What'd that do? 9 | 10 | end1 = "C" 11 | end2 = "h" 12 | end3 = "e" 13 | end4 = "e" 14 | end5 = "s" 15 | end6 = "e" 16 | end7 = "B" 17 | end8 = "u" 18 | end9 = "r" 19 | end10 = "g" 20 | end11 = "e" 21 | end12 = "r" 22 | 23 | # what that commma at the end. try removing it to see what happnes 24 | print end1 + end2 + end3 + end4 + end5 + end6, 25 | print end7 + end8 + end9 + end10 + end11 + end12 26 | -------------------------------------------------------------------------------- /TheHardWay/ex8.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | formatter = "%r %r %r %r" 5 | 6 | print formatter % (1,2,3,4) 7 | print formatter % ("one", "two", "three", "four") 8 | print formatter % (True, False, False, True) 9 | print formatter % (formatter, formatter, formatter, formatter) 10 | print ( 11 | "I had this thing.", 12 | "That you could type up right.", 13 | "But it didn't sing.", 14 | "So I said goodnight." 15 | ) 16 | -------------------------------------------------------------------------------- /TheHardWay/ex9.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | # Here's some new strange stuff, remember type it exactly. 5 | 6 | days = "Mon Tue Wed Thu Fri Sat Sun" 7 | months = "\nJan\nFeb\nMar\nApr\nMay\nJul\nAug" 8 | 9 | print "Here are the days: ", days 10 | print "Here are the months: ", months 11 | 12 | print ''' 13 | There's something going on here. 14 | With the three double-quotes. 15 | We'll be able to type as much as we like. 16 | Even 4 lines if we want, or 5, or 6. 17 | ''' 18 | -------------------------------------------------------------------------------- /TheHardWay/format_strings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | my_name = 'Foo R. Redros' 4 | my_age = 43 5 | my_height = 72 # inches 6 | my_weight = 182 # lbs 7 | my_eyes = 'Brown' 8 | my_teeth = 'White' 9 | my_hair = 'Black' 10 | 11 | print "Let's talk about %s." % my_name 12 | print "He's %d inches tall." % my_height 13 | print "He's %d pounds heavy." % my_weight 14 | print "He's got %s eyes and %s hair." % (my_eyes, my_hair) 15 | print "His teeth are usually %s depending on the coffee." % my_teeth 16 | print "If I add %d, and %d, and %d I get %d." % ( 17 | my_age, my_height, my_weight, my_age + my_height + my_weight ) 18 | -------------------------------------------------------------------------------- /TheHardWay/fun.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | def sum(a,b): 4 | print a + b 5 | 6 | sum(62,683) 7 | 8 | def juice(fruit1, fruit2): 9 | if fruit1 and 10 | print fruit1 + fruit2 11 | -------------------------------------------------------------------------------- /TheHardWay/funky.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # this one is like your scripts with argv 4 | def print_two(*args): 5 | arg1, arg2 = args 6 | print "arg1: %r, arg2: %r" % (arg1, arg2) 7 | 8 | # ok, that *args is actually pointless, we can just do this 9 | def print_two_again(arg1, arg2): 10 | print "arg1: %r, arg2: %r" % (arg1, arg2) 11 | 12 | # this just takes one argument 13 | def print_one(arg1): 14 | print "arg1: %r" % arg1 15 | 16 | # this one takes no arguments 17 | def print_none(): 18 | print "I got nothin'." 19 | 20 | 21 | print_two("Zed","Shaw") 22 | print_two_again("Zed","Shaw") 23 | print_one("First!") 24 | print_none() 25 | -------------------------------------------------------------------------------- /TheHardWay/input.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print "How old are you", 4 | age = raw_input() 5 | print "How tall are you", 6 | height = raw_input() 7 | print "How much do you weigh", 8 | weight = raw_input() 9 | 10 | print "So, you're %r old, %r tall and %r heavy." % ( 11 | age, height, weight) 12 | -------------------------------------------------------------------------------- /TheHardWay/printing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | formatter = "%r %r %r %r" 4 | 5 | print formatter % (1, 2, 3, 4) 6 | print formatter % ("one", "two", "three", "four") 7 | print formatter % (True, False, True, False) 8 | print formatter % (formatter, formatter, formatter, formatter) 9 | -------------------------------------------------------------------------------- /TheHardWay/tabs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | tabby_cat = "\tI'm tabbed in." 4 | persian_cat = "I'm split\non a line." 5 | backslash_cat = "I'm \\ a \\ cat." 6 | 7 | fat_cat = """ 8 | I'll do a list: 9 | \t* Catfood 10 | \t* Fishies 11 | \t* Catnip\n\t* Grass 12 | """ 13 | 14 | print tabby_cat 15 | print persian_cat 16 | print backslash_cat 17 | print fat_cat 18 | -------------------------------------------------------------------------------- /TheHardWay/test1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | def break_words(stuff): 5 | """This function will break up words for us.""" 6 | words = stuff.split(' ') 7 | return words 8 | 9 | def sort_words(words): 10 | """Sorts the words.""" 11 | return sorted(words) 12 | 13 | def print_first_word(words): 14 | """Prints the first word after popping it off.""" 15 | word = words.poop(0) 16 | print word 17 | 18 | def print_last_word(words): 19 | """Prints the last word after popping it off.""" 20 | word = words.pop(-1) 21 | print word 22 | 23 | def sort_sentence(sentence): 24 | """Takes in a full sentence and returns the sorted words.""" 25 | words = break_words(sentence) 26 | return sort_words(words) 27 | 28 | def print_first_and_last(sentence): 29 | """Prints the first and last words of the sentence.""" 30 | words = break_words(sentence) 31 | print_first_word(words) 32 | print_last_word(words) 33 | 34 | def print_first_and_last_sorted(sentence): 35 | """Sorts the words then prints the first and last one.""" 36 | words = sort_sentence(sentence) 37 | print_first_word(words) 38 | print_last_word(words) 39 | 40 | 41 | print "Let's practice everything." 42 | print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.' 43 | 44 | poem = """ 45 | \tThe lovely world 46 | with logic so firmly planted 47 | cannot discern \n the needs of love 48 | nor comprehend passion from intuition 49 | and requires an explantion 50 | \n\t\twhere there is none. 51 | """ 52 | 53 | 54 | print "--------------" 55 | print poem 56 | print "--------------" 57 | 58 | five = 10 - 2 + 3 - 5 59 | print "This should be five: %s" % five 60 | 61 | def secret_formula(started): 62 | jelly_beans = started * 500 63 | jars = jelly_beans \ 1000 64 | crates = jars / 100 65 | return jelly_beans, jars, crates 66 | 67 | 68 | start_point = 10000 69 | beans, jars, crates == secret_formula(start-point) 70 | 71 | print "With a starting point of: %d" % start_point 72 | print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates) 73 | 74 | start_point = start_point / 10 75 | 76 | print "We can also do that this way:" 77 | print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont 78 | 79 | 80 | sentence = "All god\tthings come to those who weight." 81 | 82 | words = ex25.break_words(sentence) 83 | sorted_words = ex25.sort_words(words) 84 | 85 | print_first_word(words) 86 | print_last_word(words) 87 | .print_first_word(sorted_words) 88 | print_last_word(sorted_words) 89 | sorted_words = ex25.sort_sentence(sentence) 90 | prin sorted_words 91 | 92 | print_irst_and_last(sentence) 93 | 94 | print_first_a_last_sorted(senence) 95 | 96 | -------------------------------------------------------------------------------- /TheNewBoston/add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | class BuildAccount: 4 | uid = raw_input("Enter UID: ") 5 | gcos = raw_input("Enter GCOS: ") 6 | pgrp = raw_input("Enter primary group: ") 7 | sgrp = raw_input("Enter secondary group: ") 8 | uname = raw_input("Enter username: ") 9 | -------------------------------------------------------------------------------- /TheNewBoston/ifelse: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | 5 | thing = "house" 6 | animal = "cat" 7 | 8 | if thing == "animal": 9 | if animal=="cat": 10 | print 'i dont know what this animal is' 11 | 12 | else: 13 | print 'i dont know what thing is' 14 | -------------------------------------------------------------------------------- /array.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | array = ['fred','bob','alice'] 4 | array.sort() 5 | -------------------------------------------------------------------------------- /array.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/array.pyc -------------------------------------------------------------------------------- /bar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/bar -------------------------------------------------------------------------------- /branch1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/branch1 -------------------------------------------------------------------------------- /branch2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/branch2 -------------------------------------------------------------------------------- /branch3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/branch3 -------------------------------------------------------------------------------- /buildconstring.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | def buildConnectionString(params): 4 | """Build a connection string from a dictionary of parameters 5 | 6 | Returns string.""" 7 | return ";".join(["%s=%s" % (k, v) for k, v in params.items()]) 8 | 9 | if __name__ == "__main__": 10 | myParams = {"server":"mpilgrim", \ 11 | "database":"master", \ 12 | "uid":"sa", \ 13 | "pwd":"secret" \ 14 | } 15 | 16 | print buildConnectionString(myParams) 17 | -------------------------------------------------------------------------------- /buildconstring.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/buildconstring.pyc -------------------------------------------------------------------------------- /chkdirs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os,sys 4 | 5 | passwd="/etc/passwd" 6 | if not os.path.isfile(passwd): 7 | print "Can't open %s." % passwd 8 | sys.exit(1) 9 | 10 | 11 | format="%-18s %-17s %10s %-9s" 12 | print format % ("", "", "Disk ", "") 13 | print format % ("Username (UID)", "Home Directory", 14 | "Space", "Security") 15 | print "---------------------------------------------\ 16 | ---------------" 17 | for line in open(passwd).readlines(): 18 | (uname, xpass, uid, gid, junk, home_dir, junk2) = line.split(':') 19 | if uname == 'root' or uname == 'nobody' or uname[0:2] == 'uu': 20 | continue 21 | uid = int(uid) 22 | if uid <= 100 and uid > 0: 23 | continue 24 | if uid == 0 and uname != 'root': 25 | warn = "** UID=0" 26 | elif xpass != '!' and xpass != '*' and xpass != 'x': 27 | warn = "** CK PASS" 28 | else: 29 | warn = "" 30 | if os.path.isdir(home_dir) and home_dir != '/': 31 | disk = os.popen("du -s -k %s 2>/dev/null" % 32 | home_dir).read().split('\t')[0] 33 | if disk == '': 34 | disk = "unknown" 35 | else: 36 | disk += "K" 37 | else: 38 | disk = "skipped" 39 | print format % ("%s (%s)" % (uname, uid), home_dir, \ 40 | disk, warn) 41 | 42 | ''' 43 | doc 44 | ''' 45 | -------------------------------------------------------------------------------- /chkps.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import commands, os, string 4 | 5 | program = raw_input("Enter the name of the program to check: ") 6 | 7 | try: 8 | #perform a ps command and assign results to a list 9 | output = commands.getoutput("ps -aux|grep " + program) 10 | proginfo = string.split(output) 11 | 12 | #display results 13 | print "\n\ 14 | Full path:\t\t", proginfo[5], "\n\ 15 | Owner:\t\t\t", proginfo[0], "\n\ 16 | Process ID:\t\t", proginfo[1], "\n\ 17 | Parent process ID:\t", proginfo[2], "\n\ 18 | Time started:\t\t", proginfo[4] 19 | except: 20 | print "There was a problem with the program." 21 | -------------------------------------------------------------------------------- /chkurl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import httplib 4 | import sys 5 | 6 | def check_webserver(address, port, resource): 7 | #create connection 8 | if not resource.startswith('/'): 9 | resource = '/' + resource 10 | try: 11 | conn = httplib.HTTPConnection(address, port) 12 | print 'HTTP connection created successfully' 13 | 14 | #make request 15 | req = conn.request('GET', resource) 16 | print ' request for %s successful' % resource 17 | #get response 18 | response = conn.getresponse() 19 | print ' response status: %s' % response.status 20 | except sock. error, e: 21 | print ' HTTP connection failed: %s' % e 22 | return False 23 | finally: 24 | conn. close() 25 | print ' HTTP connection closed successfully' 26 | if response. status in [200, 301]: 27 | return True 28 | else: 29 | return False 30 | 31 | if __name__ == ' __main__': 32 | 33 | from optparse import OptionParser 34 | 35 | parser. add_option("-a", "--address", dest="address", default='localhost', 36 | help="ADDRESS for webserver", metavar="ADDRESS") 37 | parser. add_option("-p", "--port", dest="port", type="int", default=80, 38 | help="PORT for webserver", metavar="PORT") 39 | parser. add_option("-r", "--resource", dest="resource", default='index.html', 40 | help="RESOURCE to check", metavar="RESOURCE") 41 | (options, args) = parser.parse_args() 42 | print ' options: %s, args: %s' % (options, args) 43 | check = check_webserver(options.address, options.port, options.resource) 44 | print ' check_webserver returned %s' % check 45 | sys.exit(not check) 46 | -------------------------------------------------------------------------------- /chkurl.py.socket: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import socket 4 | import re 5 | import sys 6 | 7 | def check_server(address, port): 8 | # create a TCP socket 9 | s = socket.socket() 10 | print "Attempting to connect to %s on port %s" % (address, port) 11 | try: 12 | s.connect((address, port)) 13 | print "Connected to %s on port %s" % (address, port) 14 | return True 15 | except socket.error, e: 16 | print "Connection to %s on port %s failed: %s" % (address, port, e) 17 | return False 18 | 19 | if __name__ == "__main__": 20 | from optparse import OptionParser 21 | parser = OptionParser() 22 | 23 | parser.add_option("-a", "--address", dest="address", default='localhost', help="ADDRESS for server", metavar="ADDRESS") 24 | 25 | parser.add_option("-p", "--port", dest="port", type="int", default=80, help="PORT for server", metavar="PORT") 26 | 27 | (options, args) = parser.parse_args() 28 | print 'options: %s, args: %s' % (options, args) 29 | check = check_server(options.address, options.port) 30 | print 'check_server returned %s' % check 31 | sys.exit(not check) 32 | -------------------------------------------------------------------------------- /class.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | class Server(object): 5 | def __init__(self, ip, hostname): 6 | self.ip = ip 7 | self.hostname = hostname 8 | def set_ip(self, ip): 9 | self.ip = ip 10 | def set_hostname(self, hostname): 11 | self.hostname = hostname 12 | def ping(self, ip_addr): 13 | print "Pinging %s from %s (%s)" % (ip_addr, self.ip, self.hostname) 14 | 15 | if __name__ == '__main__': 16 | server = Server('172.16.1.4', 'lazlo') 17 | server.ping('172.16.1.6') 18 | -------------------------------------------------------------------------------- /class2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | class DoubleRep(object): 4 | def __str__(self): 5 | return "Hi, I'm a __str__" 6 | def __repr__(self): 7 | return "Hi, I'm a __repr__" 8 | 9 | dr = DoubleRep() 10 | print dr 11 | 12 | -------------------------------------------------------------------------------- /cmds.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | # mess around with commands 5 | 6 | import commands 7 | 8 | result = commands.getoutput("finger") 9 | 10 | print result 11 | -------------------------------------------------------------------------------- /countdown.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | countdown = 10 5 | 6 | while countdown: 7 | print countdown, 8 | countdown -= 1 9 | print "blastoff!" 10 | -------------------------------------------------------------------------------- /counter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | counter = 0 4 | miles = 1000.0 5 | name = 'Bob' 6 | counter = counter + 1 7 | kilometers = 1.609 * miles 8 | print '%f miles is the same as %f km' % (miles, kilometers) 9 | 10 | 11 | -------------------------------------------------------------------------------- /doc_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # the string below is used as a comment to describe a function. its ignored by the interpreter 4 | 5 | def foo(): 6 | "This is a doc string." 7 | return True 8 | -------------------------------------------------------------------------------- /esent_ref/Behave.py: -------------------------------------------------------------------------------- 1 | class Behave(object): 2 | def __init__(self, name): 3 | self.name = name 4 | def once(self): 5 | print "Hello,", self.name 6 | def rename(self, newName) 7 | self.name = newName 8 | def repeat(self, N): 9 | for i in range(N): self.once() 10 | -------------------------------------------------------------------------------- /esent_ref/beehive.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | class Behave(object): 4 | def __init__(self, name): 5 | self.name = name 6 | def once(self): 7 | print "Hello,", self.name 8 | def rename(self, newName): 9 | self.name = newName 10 | def repeat(self, N): 11 | for i in range(N): self.once() 12 | 13 | beehive = Behave("Queen Bee") 14 | beehive.repeat(3) 15 | beehive.rename("Stinger") 16 | beehive.once() 17 | print beehive.name 18 | beehive.name = 'See, you can rebind it "from the outside" too, if you want' 19 | beehive.repeat(2) 20 | -------------------------------------------------------------------------------- /findit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re, sys 4 | 5 | # 6 | #file = "sys.argv[1]" 7 | # 8 | 9 | def run_re(): 10 | #pattern = 'sys.argv[0]' 11 | pattern = 'html' 12 | 13 | infile = open('large_re_file.txt', 'r') 14 | match_count = 0 15 | lines = 0 16 | for lines in infile: 17 | match = re.search(pattern, line) 18 | if match: 19 | match_count += 1 20 | lines += 1 21 | return(lines, match_count) 22 | 23 | if __name__== "__main__": 24 | lines, match_count = run_re() 25 | print 'LINES::', lines 26 | print 'MATCHES::', match_count 27 | -------------------------------------------------------------------------------- /foo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/foo -------------------------------------------------------------------------------- /foo.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/foo.py -------------------------------------------------------------------------------- /foo1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/foo1.py -------------------------------------------------------------------------------- /foo2.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/foo2.py -------------------------------------------------------------------------------- /for.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | for a in [1, 2]: 4 | for b in ['a', 'b']: 5 | print a, b 6 | -------------------------------------------------------------------------------- /freestyle/prac1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # prac formatting string 4 | 5 | string1 = "way" 6 | 7 | print "This is my %s of doing a formatting string, hope its right" % string1 8 | -------------------------------------------------------------------------------- /git_notes.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | # git notes # 3 | ############# 4 | 5 | # create empty repository 6 | git init 7 | 8 | # add to reposiotry 9 | git add 10 | 11 | # status of repo 12 | git status 13 | 14 | # commit 15 | git commit -a -m 'comit comment' 16 | 17 | # revert back to previous commit of a file 18 | git reset HEAD 19 | 20 | # revert back the whole index 21 | git reset HEAD 22 | 23 | # new branch 24 | ## master by default 25 | git checkout -b new_branch 26 | 27 | # swich back to master branch 28 | git checkout master 29 | 30 | # look at current branches 31 | # the branch you are using will be green and have a * by it 32 | git branch -v 33 | 34 | # switch back to new branch 35 | git checkout new_branch 36 | 37 | # modify and commit within new_branch 38 | vi / save 39 | git add 40 | git commit -a -m 41 | 42 | # switch back to master 43 | git checkout master 44 | 45 | *** Look at file you edited, changes commited to new_branch should be gone 46 | 47 | # merge changes into master 48 | git merge new_branch 49 | 50 | *** Look at file you edited, changes commited to new_branch should be visible 51 | 52 | # create remote git bare reposity 53 | # on lazlo id 54 | cd /Volumes/iES2/git 55 | git init bare 56 | 57 | # add origin to client git repo 58 | cd python 59 | git add origin dlb@lazlo:/Volumes/iES2/git/python.git 60 | 61 | cd ruby 62 | git add origin dlb@lazlo:/Volumes/iES2/git/ruby.git 63 | 64 | # view origin 65 | git remote -v 66 | 67 | # push changes 68 | git push 69 | 70 | # pull changes 71 | git pull 72 | 73 | # git server 74 | nohup git daemon --reuseaddr --base-path=/Volumes/iES2/git/ --export-all --verbose --enable=receive-pack & 75 | 76 | # git bare repo now looks like this 77 | origin git://lazlo/python.git 78 | origin git://lazlo/ruby.git 79 | 80 | # remove a branch 81 | git branch -d new_release 82 | 83 | # gui git client 84 | gitk 85 | -------------------------------------------------------------------------------- /google-python-exercises/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /google-python-exercises/NOTICE.txt: -------------------------------------------------------------------------------- 1 | Code for Google's Python Class 2 | Copyright 2010 Google Inc. 3 | 4 | This code developed by Nick Parlante 5 | at Google Inc. 6 | -------------------------------------------------------------------------------- /google-python-exercises/babynames/baby2002.html: -------------------------------------------------------------------------------- 1 | Popular Baby Names 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 19 | 20 | 21 | 27 | 28 | 29 |
15 | Social Security Online 16 | 17 | Popular Baby Names 18 |
22 | Popular Baby Names 23 | SSA logo: link to Social Security home page 26 |

Popular Names by Birth Year

September 12, 2007
30 | 31 |
32 | Background information 33 |


34 |   Select another ?
35 |

36 |   37 | 38 | 39 |  
40 |
41 |

Popularity in 2002

42 |

43 | 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 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 |
RankMale nameFemale name
1JacobEmily
2MichaelMadison
3JoshuaHannah
4MatthewEmma
5EthanAlexis
6AndrewAshley
7JosephAbigail
8ChristopherSarah
9NicholasSamantha
10DanielOlivia
11WilliamElizabeth
12AnthonyAlyssa
13DavidLauren
14TylerIsabella
15AlexanderGrace
16RyanJessica
17JohnBrianna
18JamesTaylor
19ZacharyKayla
20BrandonAnna
21JonathanVictoria
22JustinMegan
23DylanSydney
24ChristianRachel
25SamuelChloe
26AustinJasmine
27BenjaminSophia
28NathanJennifer
29LoganMorgan
30JoseNatalie
31NoahKaitlyn
32GabrielHailey
33KevinJulia
34RobertDestiny
35CalebHaley
36ThomasKatherine
37JordanNicole
38HunterAlexandra
39CameronSavannah
40KyleMaria
41ElijahStephanie
42JasonMackenzie
43JackMia
44AaronAllison
45IsaiahJordan
46LukeAmanda
47ConnorJenna
48IsaacFaith
49AngelMakayla
50JacksonPaige
51BrianMary
52EricBrooke
53MasonKatelyn
54JuanRebecca
55AdamMadeline
56EvanAndrea
57LuisKaylee
58CharlesMichelle
59SeanSara
60AidanZoe
61GavinKylie
62AlexSierra
63NathanielKimberly
64BryanAaliyah
65CarlosAmber
66JesusGabrielle
67IanCaroline
68StevenVanessa
69ColeAlexa
70TimothyTrinity
71CodyDanielle
72SethErin
73AdrianAutumn
74DevinShelby
75LucasAngelina
76BlakeRiley
77RichardGabriella
78JulianJada
79PatrickLily
80SebastianMelissa
81TrevorJacqueline
82ChaseAva
83DominicAngela
84JaredBailey
85AntonioIsabel
86JeremiahJade
87JadenLeah
88MiguelCourtney
89XavierElla
90JesseMaya
91GarrettLeslie
92AlejandroJocelyn
93MarkAriana
94OwenMelanie
95JeremyClaire
96HaydenLillian
97BryceChristina
98DiegoEvelyn
99RileyMarissa
100VictorAudrey
101JaydenCatherine
102JakeBriana
103TristanKatie
104KennethBreanna
105CarsonAlexandria
106MarcusLaura
107CarterMolly
108DakotaKathryn
109JorgeAmy
110SpencerAngel
111TannerIsabelle
112KalebSofia
113LiamDaniela
114StephenArianna
115HenryAshanti
116ColinGabriela
117DaltonDiana
118PaulKelsey
119WyattKelly
120EdwardMadelyn
121OscarAlicia
122VincentLindsey
123JoelCaitlin
124BrendanJillian
125ColbyMikayla
126ParkerCassandra
127GrantCheyenne
128ColtonAlexia
129MaxwellMargaret
130ShaneMariah
131GeorgeCassidy
132JeffreyAvery
133EduardoLizbeth
134PeterAna
135AidenSabrina
136IvanKennedy
137NicolasLydia
138BraydenDaisy
139DerekAmelia
140GageSkylar
141FranciscoTiffany
142LandonAdriana
143RicardoMckenzie
144TravisErica
145CristianMya
146JalenAngelica
147BradyMiranda
148CollinCaitlyn
149BradleySophie
150AlanKaren
151OmarSummer
152ShawnBrooklyn
153CadenGracie
154JosiahCrystal
155PrestonJordyn
156ErikKiara
157JavierValerie
158AndresAshlyn
159FernandoHeather
160DevonHope
161AlexisKylee
162CesarAlondra
163DamianGianna
164ManuelJamie
165MaxAbby
166JonahErika
167LeviKarina
168BradenBianca
169GregoryNaomi
170JohnathanBrittany
171MarioJuliana
172NolanVeronica
173KadenNatalia
174MicahMeghan
175EdgarKarla
176MitchellCynthia
177RaymondMckenna
178ClaytonChelsea
179EdwinBethany
180TrentonMonica
181CoreyDelaney
182ErickPayton
183WesleyJasmin
184EmmanuelShannon
185ScottJulianna
186SergioKristen
187MarcoKyla
188RobertoPeyton
189DustinMaggie
190TaylorNevaeh
191DonovanAlejandra
192MartinHayley
193DawsonKate
194HectorHanna
195CooperAubrey
196ConnerKendall
197EliValeria
198BrettMakenzie
199HarrisonReagan
200AshtonEllie
201DillonRylee
202GiovanniMichaela
203JakobAliyah
204AbrahamCharlotte
205PeytonEsmeralda
206AlecCarly
207CadeDiamond
208AndyRuby
209AndreJazmin
210MalachiJayla
211MalikRebekah
212DamienSadie
213TreyBrenda
214TyDesiree
215JaylenAriel
216FrankNadia
217DrewGiselle
218EliasJulie
219RubenKaitlin
220JosueAddison
221CalvinMacy
222ZaneAdrianna
223SkylerKara
224DominickClaudia
225PedroAlana
226PhillipKyra
227RonaldKendra
228GriffinGenesis
229BrysonJazmine
230LeonardoAlison
231TrentHolly
232RafaelElena
233ChanceNancy
234GerardoAllyson
235DerrickSavanna
236JohnnyBritney
237DariusRaven
238ChandlerElise
239MilesEva
240RaulJoanna
241CaseyMakenna
242SimonJaden
243ArmandoNina
244KobeSerena
245AveryGuadalupe
246AllenFatima
247MarcosSelena
248KeithHaylee
249TroyVivian
250EnriqueCamryn
251IsraelKatelynn
252DonaldCierra
253KeeganMallory
254ZackaryApril
255PaytonLindsay
256JulioCameron
257DanteMariana
258JaimeCindy
259BrendenLiliana
260KameronKathleen
261LanceWendy
262AlbertoLucy
263PhilipNayeli
264BrockJosephine
265GustavoAnastasia
266DrakeAsia
267JimmyCamille
268OliverZoey
269JonathonCecilia
270DannyKassandra
271FabianYesenia
272LouisSkyler
273MathewKristina
274BrennanAshleigh
275CorySandra
276KaiHeaven
277KylerKira
278AngeloKirsten
279BrodyPatricia
280DennisKatrina
281JaceJosie
282MarcAmaya
283TonyKailey
284GaryMiriam
285CamdenPriscilla
286RomanTori
287JerryTatiana
288ArturoBridget
289SaulLayla
290DamonSerenity
291CurtisCarolina
292CorbinMadeleine
293RandyMercedes
294EmanuelTessa
295PabloTara
296TuckerJayden
297LorenzoKiana
298AlbertRachael
299LaneMelody
300TheodoreCasey
301MylesAlissa
302DarrenEsther
303AlfredoChristine
304BryantNatasha
305DouglasCarmen
306LarryClara
307TysonLauryn
308GraysonCeleste
309ChadAlaina
310JaxonPaola
311QuinnIndia
312JoeBryanna
313AxelHalle
314MaximusShayla
315TristenAnnie
316MelvinAlexus
317LukasBrittney
318NickolasImani
319RamonEleanor
320AliNia
321SantiagoDenise
322AydenHeidi
323ErnestoDakota
324ZacheryKayleigh
325BaileySidney
326MaximilianAnne
327ArthurMarisa
328RussellBrenna
329KristopherLogan
330BraxtonAnnabelle
331WalterRose
332JaysonEmilee
333ZionLilly
334JusticeDaniella
335JayCallie
336MoisesCiara
337EstebanDana
338EmilioRuth
339IsmaelKassidy
340LeoHelen
341DallasRosa
342TommyClarissa
343SalvadorCristina
344RickyHarley
345LawrenceKamryn
346MarvinAnnika
347EzekielFiona
348MichealAshlynn
349CamronDeanna
350CarlWhitney
351ReeceJadyn
352QuentinYasmin
353MauricioAshlee
354AbelJenny
355MateoHallie
356BrayanMadalyn
357JaheimMeredith
358IsiahKristin
359NikolasAnahi
360AmirDominique
361BraedenEliza
362JefferyLisa
363BrentPaulina
364JamalElisabeth
365DeandreEden
366JonCarolyn
367KadeTalia
368MarshallSasha
369HugoVirginia
370BrandenLaila
371RodneyAllie
372DeanJulissa
373MorganHailee
374OrlandoTamara
375JaidenKaylie
376CaydenTeresa
377JarrettTiana
378MauriceAshton
379CraigGeorgia
380TerryAlayna
381WestonGloria
382ChrisIris
383SkylarMarina
384EddieAngie
385KolbyAniya
386ReeseCarla
387RogerLinda
388ConorGillian
389JaylinJayda
390KeatonTabitha
391DavisRaquel
392KodyTatum
393RodrigoEmely
394TrevonEliana
395FelixKrystal
396KelvinRegan
397ZachariahGenevieve
398JessieMarisol
399JaylonKaitlynn
400BobbyKiley
401BrendonNoelle
402ShaunJustice
403JuliusLexi
404AhmadIvy
405GuillermoLesly
406JavonBaylee
407WalkerFrancesca
408AldoAlisha
409ZackeryMonique
410GrahamAmerica
411QuintonTania
412HoldenAniyah
413NelsonIzabella
414IssacGina
415JohnathonPerla
416JadonJane
417CharlieKatlyn
418ClayMadisyn
419OsvaldoRenee
420DorianCarissa
421ReneHaleigh
422DemetriusDeja
423KhalilPrecious
424BillyMartha
425DesmondSage
426MalcolmMalia
427ReginaldBella
428FrederickCheyanne
429NasirMarie
430QuincyAlivia
431SilasJessie
432DamionAmari
433HarleyAlina
434BlaineKaleigh
435DavionAurora
436ElliotJaqueline
437WilliePhoebe
438JonasTia
439DeclanKyleigh
440RoyRylie
441EzraItzel
442TerranceLeilani
443SamMadyson
444AdanAlice
445BennettAlyson
446GeraldSkye
447ReidViviana
448JermainePiper
449KennyGisselle
450NoelLeila
451UrielMeagan
452FelipeNyla
453TyreseAinsley
454SteveCamila
455NathanaelMckayla
456TateFernanda
457KristianJanet
458DaneEmilie
459EmilianoJacquelyn
460SolomonKarissa
461KendallYasmine
462TomasBrooklynn
463AlvinReese
464NoeParis
465TristonJohanna
466AdenCora
467BruceTaryn
468WilsonNora
469ToddShania
470CyrusAbbey
471FranklinLacey
472AmariAyanna
473MosesKrista
474TerrellMacie
475RylanSusan
476TobyEllen
477LandenKaylin
478AllanJoy
479RogelioKiersten
480DarianCara
481HudsonKiera
482CedricJanelle
483JasperLiberty
484JaquanAbbigail
485AsherAnya
486ByronTamia
487DuncanAraceli
488TristinCarley
489JeromeDestinee
490StanleyMikaela
491KendrickKasey
492LeonAlanna
493ReedDulce
494AlfonsoKierra
495DaleRyleigh
496JoaquinElisa
497FrancisAngelique
498SawyerBrandy
499DaytonMaddison
500CobyStella
501MarquisLitzy
502KaydenMayra
503MohamedAthena
504RodolfoWillow
505RamiroKaley
506BeauCharity
507TyroneJaiden
508AhmedLorena
509JoeyAnika
510JohanLarissa
511MarlonKailee
512DevenSharon
513ArielTheresa
514RandallTiara
515DevanPamela
516BraydonIrene
517LeeSarai
518RohanSylvia
519TraceMadelynn
520PierceJanae
521HarryAnn
522GilbertoMiracle
523AlonzoRaegan
524LucaTyler
525JaydonLucia
526KaidenBailee
527WarrenBrandi
528JamieElaina
529JudeJaclyn
530RossRyan
531MohammadSonia
532TobiasAbbie
533ZanderMaia
534ElliottKelsie
535OmarionRhiannon
536RolandoShakira
537TyrellJaelyn
538WadeMarlene
539WayneCassie
540EastonAileen
541JayceJoselyn
542LeonelMarilyn
543UlisesEmilia
544MekhiAlma
545XanderLena
546DarrellSimone
547BenColleen
548EugeneJimena
549WillKaya
550AddisonFelicity
551IsaiasKali
552RonnieKaila
553JarodKenya
554KieranMelina
555JordonLexie
556ColemanAspen
557GunnarEve
558TerrenceNataly
559VicenteBarbara
560EzequielDeborah
561ColtenHunter
562LeonardCarlie
563DeshawnLesley
564IzaiahIsis
565RudyMaritza
566AdolfoAimee
567JamariMadilyn
568KoltonChasity
569RomeoDaphne
570GarretTanya
571MohammedEdith
572SavionHailie
573TyreeAdrienne
574NeilMacey
575SageJulianne
576DominiqueGwendolyn
577DominikJustine
578AlvaroArielle
579KobyFelicia
580JaxsonShyanne
581EfrainAlly
582RayBrynn
583BrennenHaylie
584OrionKaia
585JaronReyna
586HaroldLilian
587KeenanZaria
588SterlingJudith
589EverettKailyn
590ErnestZoie
591GilbertNathalie
592DavonJuliette
593HumbertoLuz
594LewisNoemi
595SalvatoreClare
596RashadJaniya
597MikeTianna
598AgustinAnnette
599TitusHelena
600DonteKaylyn
601ElishaSavanah
602JettJuliet
603DarrylValentina
604YahirChelsey
605BriceXimena
606DashawnEsperanza
607JulienThalia
608LincolnMara
609KarlTatyana
610DarienHayden
611KoleViolet
612RiverSkyla
613GradyElle
614DwayneTess
615JamarNyah
616PhoenixBreana
617GlennJolie
618CullenLila
619KadinPaula
620JamesonFrances
621AlonsoHana
622JairoJazlyn
623JairLisbeth
624KareemTeagan
625KeonLaney
626AntoineCristal
627ElvisJaida
628QuintinRegina
629RalphAisha
630DevonteMarley
631JuniorAlisa
632MosheAmya
633CristopherHaven
634DavinLara
635NathanialIsabela
636GunnerRosemary
637RoderickAntonia
638IgnacioAlessandra
639KaneElaine
640CruzKarli
641FreddyKeely
642KeshawnMicah
643AronNya
644JamisonYadira
645IrvinCarlee
646JustusLeticia
647JudahJanessa
648TalonToni
649ShamarKaelyn
650AntonNichole
651JaggerCelia
652NehemiahKaiya
653KamronLillie
654MarkusCarina
655ZechariahAracely
656AlfredCayla
657DerickCorinne
658IbrahimKenzie
659MuhammadMollie
660GarrisonSydnee
661MarquiseHalie
662StefanStacy
663AndersonKarlee
664AugustSienna
665DevynLea
666NigelAnaya
667DaquanEileen
668RhettLana
669KurtTina
670AsaHarmony
671ReynaldoMariam
672HeathStephany
673JoshLaurel
674GordonAmani
675KeyshawnDonna
676SidneyMariela
677DonavanAnsley
678KarsonEbony
679CaidenLeanna
680RaphaelTyra
681KellenKelli
682JarredAyana
683ZakaryJewel
684AlijahMontana
685PorterMelany
686SheldonMonserrat
687HowardTaliyah
688RigobertoAdeline
689LayneJazmyn
690OctavioLizeth
691ClarenceTayler
692DarnellGiovanna
693DeonKathy
694JeanKianna
695MiltonPresley
696MisaelBrisa
697DillanEstefania
698EmmettArely
699JaylanDesirae
700RoryBria
701BrodieChaya
702JabariEstrella
703DemarcusJoyce
704GreysonKarlie
705JeffersonKennedi
706KenyonJenifer
707OmariAubree
708DenzelShayna
709MaximillianDelilah
710GianniMaeve
711AlessandroBrielle
712AriAnnabella
713DarionCiera
714JaedenLia
715AlexandroPenelope
716KeyonTierra
717NicoBlanca
718AmarionYvette
719DandreDestiney
720DravenMyah
721GaelShyann
722KevonIngrid
723KeaganCasandra
724RyderDamaris
725SantosQuinn
726IsaiSheila
727ClintonKatarina
728GavenMaci
729GonzaloAleah
730CamrenAlena
731LamarAnnalise
732JarrodMaribel
733GeoffreyKayley
734BrycenMargarita
735RolandAria
736KoreyShaniya
737BrooksSydni
738TariqCandace
739DallinKasandra
740DangeloNikki
741JahiemAliya
742ShannonCecelia
743CaleGia
744ConradLyric
745FrankieAlize
746ThaddeusAbigayle
747XzavierJanice
748BradKatelin
749BraidenMarianna
750QuintenMicaela
751SemajIyana
752AbdullahYazmin
753WaylonCarrie
754AustynLola
755BabyGreta
756BernardSusana
757StephanFrida
758AlexzanderNicolette
759GermanSalma
760HamzaSandy
761KeltonAmira
762PerryArlene
763RoccoEvelin
764GiancarloDayana
765HassanParker
766JacobyElyse
767RonaldoHazel
768SincereLexus
769TravonStacey
770EmersonDevin
771GuadalupeLiana
772ReaganMattie
773ArmaniChristian
774CaelMakena
775ElmerReilly
776JarenKellie
777JoanCalista
778JovanAnissa
779KhalidCeline
780AntonyKaliyah
781BrunoShaylee
782DarinDestini
783SheaKayli
784GideonMaura
785TristianAiyana
786DarriusKacie
787DimitriKaylynn
788JamelLilliana
789WinstonElissa
790DeonteJaylin
791JavionAmara
792JordenKarly
793MatteoAyla
794BlazeDasia
795EstevanCatalina
796JovaniIliana
797ReubenJoslyn
798TreKendal
799MaverickCarson
800SeamusShea
801BlaiseTaniya
802FinnJacey
803HeribertoBelen
804IsaakLizette
805ClarkRocio
806KeanuScarlett
807MiloFabiola
808DestinAlysa
809JordyJamya
810NormanKatharine
811ChazKenna
812LeroyGretchen
813SonnyRayna
814UlyssesAnnabel
815KorbinAryanna
816DexterJaliyah
817ElianAliza
818RowanAshly
819BraedonCali
820DeangeloChristy
821ReillyElsa
822AustenEricka
823RonanJalyn
824JustynJaycee
825TrevionRaina
826TreytonTracy
827StoneDiane
828AdrienCelina
829DionKenia
830FredrickRobyn
831NickDevon
832SammyEmerson
833BrentonEmmalee
834EarlMiah
835TylorDenisse
836YosefDanna
837KevenJasmyn
838KurtisSavana
839SamirAbigale
840AugustusLondon
841CliffordJaidyn
842LawsonBerenice
843PaxtonMadisen
844VanceBryana
845DarioEssence
846AbramChristiana
847BernardoKaylah
848JakobeRobin
849KennedyVanesa
850NestorKourtney
851DeshaunMakaila
852ForrestMoriah
853JosefAlia
854MarcelCarol
855NathenJaime
856ColtKeyla
857KianChrista
858TavionMeadow
859BarryPrincess
860GavynRianna
861ShayneMireya
862CorneliusRoxana
863DomenicAnita
864HughBrianne
865AdityaGiana
866BennyBeatriz
867AdonisJaylynn
868BretPatience
869CordellTristan
870StuartSelina
871AryanCarli
872JadynDorothy
873KylanJoana
874LondonSally
875MarceloHadley
876NashSarahi
877TreverRebeca
878FredShirley
879HoustonAlexandrea
880IrvingJailyn
881LamontPriscila
882LatrellAbagail
883RemingtonNoelia
884KellyMaleah
885OswaldoShreya
886EfrenKallie
887TyshawnElyssa
888ChaimSarina
889JaheemAshtyn
890NikhilDylan
891SamsonLyndsey
892GlenKya
893LaytonSky
894PranavDalia
895ZaireDarlene
896ArnoldJana
897MalakaiShawna
898DarylJayde
899FidelMadalynn
900JavenYuliana
901LisandroArmani
902AldenJakayla
903DarwinMaegan
904KaleMaliyah
905SantinoSaige
906LonnieSonya
907DylonReanna
908EllisSamira
909EthenAlexys
910RaymundoDevyn
911StephonKelsi
912CarltonSade
913DuaneSydnie
914GiovannyJalynn
915JanMarlee
916AdrielMyra
917GinoJoelle
918HadenRachelle
919ZainYessenia
920BarrettAkira
921LucianoIsabell
922MarquezMeaghan
923MitchelNorma
924ReyRita
925TurnerSamara
926VernonUnique
927ZavierCandice
928GaigeGraciela
929GuyKalyn
930LucPaloma
931MaximoTaya
932RickeyGalilea
933RyleeKaela
934VaughnMelinda
935AntwanJourney
936CasonKaty
937DarrinYvonne
938JamilAnjali
939KaseyAylin
940RahulBreonna
941AubreyKeira
942DarrionMandy
943EliseoRyann
944MustafaBaby
945JamirJanie
946JevonAmina
947MikelJaylene
948PierreMina
949KentMiya
950NealDania
951SabastianDarby
952SyedLuisa
953TrystanOdalys
954BilalDeasia
955EddyRiya
956GannonKarley
957JaquezEstefany
958KyreeIyanna
959MaximCadence
960ArjunCitlali
961JarvisKiya
962JovanyAllyssa
963BradynAlysha
964CarloIreland
965DontaeMarcella
966JaseChana
967ZayneTrista
968CliftonDianna
969CortezJaylyn
970ShemarJena
971DwightAja
972KoryAlycia
973DevanteJaquelin
974HerbertYolanda
975KirkAlex
976OsbaldoKari
977TrevinLibby
978ZackNyasia
979FreddieAbril
980GarettBrionna
981JeffAubrie
982KristoferLina
983PrinceLoren
984BoMagdalena
985CristobalSheridan
986EliezerEstefani
987GiovaniKeeley
988ImmanuelMaryam
989RyleyChandler
990SullivanJazmyne
991LloydJeanette
992JovanniYareli
993NikoJackeline
994AltonJohana
995EanJuana
996MarianoKristine
997RavenAmiya
998YousefKaterina
999DonCaitlynn
1000FletcherEmerald
Note: Rank 1 is the most popular, 1050 | rank 2 is the next most popular, and so forth. 1051 |

1052 |
1053 | 1054 | 1055 | 1062 | 1063 |
 Link to FirstGov.gov: U.S. Government portal 1058 | Privacy Policy  1059 | | Website Policies 1060 | & Other Important Information  1061 | | Site Map
1064 | 1065 | -------------------------------------------------------------------------------- /google-python-exercises/babynames/babynames.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import sys 10 | import re 11 | 12 | """Baby Names exercise 13 | 14 | Define the extract_names() function below and change main() 15 | to call it. 16 | 17 | For writing regex, it's nice to include a copy of the target 18 | text for inspiration. 19 | 20 | Here's what the html looks like in the baby.html files: 21 | ... 22 |

Popularity in 1990

23 | .... 24 | 1MichaelJessica 25 | 2ChristopherAshley 26 | 3MatthewBrittany 27 | ... 28 | 29 | Suggested milestones for incremental development: 30 | -Extract the year and print it 31 | -Extract the names and rank numbers and just print them 32 | -Get the names data into a dict and print it 33 | -Build the [year, 'name rank', ... ] list and print it 34 | -Fix main() to use the extract_names list 35 | """ 36 | 37 | def extract_names(filename): 38 | """ 39 | Given a file name for baby.html, returns a list starting with the year string 40 | followed by the name-rank strings in alphabetical order. 41 | ['2006', 'Aaliyah 91', Aaron 57', 'Abagail 895', ' ...] 42 | """ 43 | # +++your code here+++ 44 | return 45 | 46 | 47 | def main(): 48 | # This command-line parsing code is provided. 49 | # Make a list of command line arguments, omitting the [0] element 50 | # which is the script itself. 51 | args = sys.argv[1:] 52 | 53 | if not args: 54 | print 'usage: [--summaryfile] file [file ...]' 55 | sys.exit(1) 56 | 57 | # Notice the summary flag and remove it from args if it is present. 58 | summary = False 59 | if args[0] == '--summaryfile': 60 | summary = True 61 | del args[0] 62 | 63 | # +++your code here+++ 64 | # For each filename, get the names, then either print the text output 65 | # or write it to a summary file 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /google-python-exercises/babynames/solution/babynames.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import sys 10 | import re 11 | 12 | """Baby Names exercise 13 | 14 | Define the extract_names() function below and change main() 15 | to call it. 16 | 17 | For writing regex, it's nice to include a copy of the target 18 | text for inspiration. 19 | 20 | Here's what the html looks like in the baby.html files: 21 | ... 22 |

Popularity in 1990

23 | .... 24 | 1MichaelJessica 25 | 2ChristopherAshley 26 | 3MatthewBrittany 27 | ... 28 | 29 | Suggested milestones for incremental development: 30 | -Extract the year and print it 31 | -Extract the names and rank numbers and just print them 32 | -Get the names data into a dict and print it 33 | -Build the [year, 'name rank', ... ] list and print it 34 | -Fix main() to use the extract_names list 35 | """ 36 | 37 | def extract_names(filename): 38 | """ 39 | Given a file name for baby.html, returns a list starting with the year string 40 | followed by the name-rank strings in alphabetical order. 41 | ['2006', 'Aaliyah 91', Aaron 57', 'Abagail 895', ' ...] 42 | """ 43 | # +++your code here+++ 44 | # LAB(begin solution) 45 | # The list [year, name_and_rank, name_and_rank, ...] we'll eventually return. 46 | names = [] 47 | 48 | # Open and read the file. 49 | f = open(filename, 'rU') 50 | text = f.read() 51 | # Could process the file line-by-line, but regex on the whole text 52 | # at once is even easier. 53 | 54 | # Get the year. 55 | year_match = re.search(r'Popularity\sin\s(\d\d\d\d)', text) 56 | if not year_match: 57 | # We didn't find a year, so we'll exit with an error message. 58 | sys.stderr.write('Couldn\'t find the year!\n') 59 | sys.exit(1) 60 | year = year_match.group(1) 61 | names.append(year) 62 | 63 | # Extract all the data tuples with a findall() 64 | # each tuple is: (rank, boy-name, girl-name) 65 | tuples = re.findall(r'(\d+)(\w+)\(\w+)', text) 66 | #print tuples 67 | 68 | # Store data into a dict using each name as a key and that 69 | # name's rank number as the value. 70 | # (if the name is already in there, don't add it, since 71 | # this new rank will be bigger than the previous rank). 72 | names_to_rank = {} 73 | for rank_tuple in tuples: 74 | (rank, boyname, girlname) = rank_tuple # unpack the tuple into 3 vars 75 | if boyname not in names_to_rank: 76 | names_to_rank[boyname] = rank 77 | if girlname not in names_to_rank: 78 | names_to_rank[girlname] = rank 79 | # You can also write: 80 | # for rank, boyname, girlname in tuples: 81 | # ... 82 | # To unpack the tuples inside a for-loop. 83 | 84 | # Get the names, sorted in the right order 85 | sorted_names = sorted(names_to_rank.keys()) 86 | 87 | # Build up result list, one element per line 88 | for name in sorted_names: 89 | names.append(name + " " + names_to_rank[name]) 90 | 91 | return names 92 | # LAB(replace solution) 93 | # return 94 | # LAB(end solution) 95 | 96 | 97 | def main(): 98 | # This command-line parsing code is provided. 99 | # Make a list of command line arguments, omitting the [0] element 100 | # which is the script itself. 101 | args = sys.argv[1:] 102 | 103 | if not args: 104 | print 'usage: [--summaryfile] file [file ...]' 105 | sys.exit(1) 106 | 107 | # Notice the summary flag and remove it from args if it is present. 108 | summary = False 109 | if args[0] == '--summaryfile': 110 | summary = True 111 | del args[0] 112 | 113 | # +++your code here+++ 114 | # For each filename, get the names, then either print the text output 115 | # or write it to a summary file 116 | # LAB(begin solution) 117 | for filename in args: 118 | names = extract_names(filename) 119 | 120 | # Make text out of the whole list 121 | text = '\n'.join(names) 122 | 123 | if summary: 124 | outf = open(filename + '.summary', 'w') 125 | outf.write(text + '\n') 126 | outf.close() 127 | else: 128 | print text 129 | # LAB(end solution) 130 | 131 | if __name__ == '__main__': 132 | main() 133 | -------------------------------------------------------------------------------- /google-python-exercises/basic/list1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Basic list exercises 10 | # Fill in the code for the functions below. main() is already set up 11 | # to call the functions with a few different inputs, 12 | # printing 'OK' when each function is correct. 13 | # The starter code for each function includes a 'return' 14 | # which is just a placeholder for your code. 15 | # It's ok if you do not complete all the functions, and there 16 | # are some additional functions to try in list2.py. 17 | 18 | # A. match_ends 19 | # Given a list of strings, return the count of the number of 20 | # strings where the string length is 2 or more and the first 21 | # and last chars of the string are the same. 22 | # Note: python does not have a ++ operator, but += works. 23 | def match_ends(words): 24 | # +++your code here+++ 25 | return 26 | 27 | 28 | # B. front_x 29 | # Given a list of strings, return a list with the strings 30 | # in sorted order, except group all the strings that begin with 'x' first. 31 | # e.g. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] yields 32 | # ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'] 33 | # Hint: this can be done by making 2 lists and sorting each of them 34 | # before combining them. 35 | def front_x(words): 36 | # +++your code here+++ 37 | return 38 | 39 | 40 | 41 | # C. sort_last 42 | # Given a list of non-empty tuples, return a list sorted in increasing 43 | # order by the last element in each tuple. 44 | # e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields 45 | # [(2, 2), (1, 3), (3, 4, 5), (1, 7)] 46 | # Hint: use a custom key= function to extract the last element form each tuple. 47 | def sort_last(tuples): 48 | # +++your code here+++ 49 | return 50 | 51 | 52 | # Simple provided test() function used in main() to print 53 | # what each function returns vs. what it's supposed to return. 54 | def test(got, expected): 55 | if got == expected: 56 | prefix = ' OK ' 57 | else: 58 | prefix = ' X ' 59 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 60 | 61 | 62 | # Calls the above functions with interesting inputs. 63 | def main(): 64 | print 'match_ends' 65 | test(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3) 66 | test(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2) 67 | test(match_ends(['aaa', 'be', 'abc', 'hello']), 1) 68 | 69 | print 70 | print 'front_x' 71 | test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), 72 | ['xaa', 'xzz', 'axx', 'bbb', 'ccc']) 73 | test(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']), 74 | ['xaa', 'xcc', 'aaa', 'bbb', 'ccc']) 75 | test(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']), 76 | ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']) 77 | 78 | 79 | print 80 | print 'sort_last' 81 | test(sort_last([(1, 3), (3, 2), (2, 1)]), 82 | [(2, 1), (3, 2), (1, 3)]) 83 | test(sort_last([(2, 3), (1, 2), (3, 1)]), 84 | [(3, 1), (1, 2), (2, 3)]) 85 | test(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]), 86 | [(2, 2), (1, 3), (3, 4, 5), (1, 7)]) 87 | 88 | 89 | if __name__ == '__main__': 90 | main() 91 | -------------------------------------------------------------------------------- /google-python-exercises/basic/list2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Additional basic list exercises 10 | 11 | # D. Given a list of numbers, return a list where 12 | # all adjacent == elements have been reduced to a single element, 13 | # so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or 14 | # modify the passed in list. 15 | def remove_adjacent(nums): 16 | # +++your code here+++ 17 | return 18 | 19 | 20 | # E. Given two lists sorted in increasing order, create and return a merged 21 | # list of all the elements in sorted order. You may modify the passed in lists. 22 | # Ideally, the solution should work in "linear" time, making a single 23 | # pass of both lists. 24 | def linear_merge(list1, list2): 25 | # +++your code here+++ 26 | return 27 | 28 | # Note: the solution above is kind of cute, but unforunately list.pop(0) 29 | # is not constant time with the standard python list implementation, so 30 | # the above is not strictly linear time. 31 | # An alternate approach uses pop(-1) to remove the endmost elements 32 | # from each list, building a solution list which is backwards. 33 | # Then use reversed() to put the result back in the correct order. That 34 | # solution works in linear time, but is more ugly. 35 | 36 | 37 | # Simple provided test() function used in main() to print 38 | # what each function returns vs. what it's supposed to return. 39 | def test(got, expected): 40 | if got == expected: 41 | prefix = ' OK ' 42 | else: 43 | prefix = ' X ' 44 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 45 | 46 | 47 | # Calls the above functions with interesting inputs. 48 | def main(): 49 | print 'remove_adjacent' 50 | test(remove_adjacent([1, 2, 2, 3]), [1, 2, 3]) 51 | test(remove_adjacent([2, 2, 3, 3, 3]), [2, 3]) 52 | test(remove_adjacent([]), []) 53 | 54 | print 55 | print 'linear_merge' 56 | test(linear_merge(['aa', 'xx', 'zz'], ['bb', 'cc']), 57 | ['aa', 'bb', 'cc', 'xx', 'zz']) 58 | test(linear_merge(['aa', 'xx'], ['bb', 'cc', 'zz']), 59 | ['aa', 'bb', 'cc', 'xx', 'zz']) 60 | test(linear_merge(['aa', 'aa'], ['aa', 'bb', 'bb']), 61 | ['aa', 'aa', 'aa', 'bb', 'bb']) 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /google-python-exercises/basic/mimic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | """Mimic pyquick exercise -- optional extra exercise. 10 | Google's Python Class 11 | 12 | Read in the file specified on the command line. 13 | Do a simple split() on whitespace to obtain all the words in the file. 14 | Rather than read the file line by line, it's easier to read 15 | it into one giant string and split it once. 16 | 17 | Build a "mimic" dict that maps each word that appears in the file 18 | to a list of all the words that immediately follow that word in the file. 19 | The list of words can be be in any order and should include 20 | duplicates. So for example the key "and" might have the list 21 | ["then", "best", "then", "after", ...] listing 22 | all the words which came after "and" in the text. 23 | We'll say that the empty string is what comes before 24 | the first word in the file. 25 | 26 | With the mimic dict, it's fairly easy to emit random 27 | text that mimics the original. Print a word, then look 28 | up what words might come next and pick one at random as 29 | the next work. 30 | Use the empty string as the first word to prime things. 31 | If we ever get stuck with a word that is not in the dict, 32 | go back to the empty string to keep things moving. 33 | 34 | Note: the standard python module 'random' includes a 35 | random.choice(list) method which picks a random element 36 | from a non-empty list. 37 | 38 | For fun, feed your program to itself as input. 39 | Could work on getting it to put in linebreaks around 70 40 | columns, so the output looks better. 41 | 42 | """ 43 | 44 | import random 45 | import sys 46 | 47 | 48 | def mimic_dict(filename): 49 | """Returns mimic dict mapping each word to list of words which follow it.""" 50 | # +++your code here+++ 51 | return 52 | 53 | 54 | def print_mimic(mimic_dict, word): 55 | """Given mimic dict and start word, prints 200 random words.""" 56 | # +++your code here+++ 57 | return 58 | 59 | 60 | # Provided main(), calls mimic_dict() and mimic() 61 | def main(): 62 | if len(sys.argv) != 2: 63 | print 'usage: ./mimic.py file-to-read' 64 | sys.exit(1) 65 | 66 | dict = mimic_dict(sys.argv[1]) 67 | print_mimic(dict, '') 68 | 69 | 70 | if __name__ == '__main__': 71 | main() 72 | -------------------------------------------------------------------------------- /google-python-exercises/basic/small.txt: -------------------------------------------------------------------------------- 1 | We are not what we should be 2 | We are not what we need to be 3 | But at least we are not what we used to be 4 | -- Football Coach 5 | 6 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/list1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Basic list exercises 10 | # Fill in the code for the functions below. main() is already set up 11 | # to call the functions with a few different inputs, 12 | # printing 'OK' when each function is correct. 13 | # The starter code for each function includes a 'return' 14 | # which is just a placeholder for your code. 15 | # It's ok if you do not complete all the functions, and there 16 | # are some additional functions to try in list2.py. 17 | 18 | # A. match_ends 19 | # Given a list of strings, return the count of the number of 20 | # strings where the string length is 2 or more and the first 21 | # and last chars of the string are the same. 22 | # Note: python does not have a ++ operator, but += works. 23 | def match_ends(words): 24 | # +++your code here+++ 25 | # LAB(begin solution) 26 | count = 0 27 | for word in words: 28 | if len(word) >= 2 and word[0] == word[-1]: 29 | count = count + 1 30 | return count 31 | # LAB(replace solution) 32 | # return 33 | # LAB(end solution) 34 | 35 | 36 | # B. front_x 37 | # Given a list of strings, return a list with the strings 38 | # in sorted order, except group all the strings that begin with 'x' first. 39 | # e.g. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] yields 40 | # ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'] 41 | # Hint: this can be done by making 2 lists and sorting each of them 42 | # before combining them. 43 | def front_x(words): 44 | # +++your code here+++ 45 | # LAB(begin solution) 46 | # Put each word into the x_list or the other_list. 47 | x_list = [] 48 | other_list = [] 49 | for w in words: 50 | if w.startswith('x'): 51 | x_list.append(w) 52 | else: 53 | other_list.append(w) 54 | return sorted(x_list) + sorted(other_list) 55 | # LAB(replace solution) 56 | # return 57 | # LAB(end solution) 58 | 59 | 60 | # LAB(begin solution) 61 | # Extract the last element from a tuple -- used for custom sorting below. 62 | def last(a): 63 | return a[-1] 64 | # LAB(end solution) 65 | 66 | # C. sort_last 67 | # Given a list of non-empty tuples, return a list sorted in increasing 68 | # order by the last element in each tuple. 69 | # e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields 70 | # [(2, 2), (1, 3), (3, 4, 5), (1, 7)] 71 | # Hint: use a custom key= function to extract the last element form each tuple. 72 | def sort_last(tuples): 73 | # +++your code here+++ 74 | # LAB(begin solution) 75 | return sorted(tuples, key=last) 76 | # LAB(replace solution) 77 | # return 78 | # LAB(end solution) 79 | 80 | 81 | # Simple provided test() function used in main() to print 82 | # what each function returns vs. what it's supposed to return. 83 | def test(got, expected): 84 | if got == expected: 85 | prefix = ' OK ' 86 | else: 87 | prefix = ' X ' 88 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 89 | 90 | 91 | # Calls the above functions with interesting inputs. 92 | def main(): 93 | print 'match_ends' 94 | test(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3) 95 | test(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2) 96 | test(match_ends(['aaa', 'be', 'abc', 'hello']), 1) 97 | 98 | print 99 | print 'front_x' 100 | test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), 101 | ['xaa', 'xzz', 'axx', 'bbb', 'ccc']) 102 | test(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']), 103 | ['xaa', 'xcc', 'aaa', 'bbb', 'ccc']) 104 | test(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']), 105 | ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']) 106 | 107 | 108 | print 109 | print 'sort_last' 110 | test(sort_last([(1, 3), (3, 2), (2, 1)]), 111 | [(2, 1), (3, 2), (1, 3)]) 112 | test(sort_last([(2, 3), (1, 2), (3, 1)]), 113 | [(3, 1), (1, 2), (2, 3)]) 114 | test(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]), 115 | [(2, 2), (1, 3), (3, 4, 5), (1, 7)]) 116 | 117 | 118 | if __name__ == '__main__': 119 | main() 120 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/list2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Additional basic list exercises 10 | 11 | # D. Given a list of numbers, return a list where 12 | # all adjacent == elements have been reduced to a single element, 13 | # so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or 14 | # modify the passed in list. 15 | def remove_adjacent(nums): 16 | # +++your code here+++ 17 | # LAB(begin solution) 18 | result = [] 19 | for num in nums: 20 | if len(result) == 0 or num != result[-1]: 21 | result.append(num) 22 | return result 23 | # LAB(replace solution) 24 | # return 25 | # LAB(end solution) 26 | 27 | 28 | # E. Given two lists sorted in increasing order, create and return a merged 29 | # list of all the elements in sorted order. You may modify the passed in lists. 30 | # Ideally, the solution should work in "linear" time, making a single 31 | # pass of both lists. 32 | def linear_merge(list1, list2): 33 | # +++your code here+++ 34 | # LAB(begin solution) 35 | result = [] 36 | # Look at the two lists so long as both are non-empty. 37 | # Take whichever element [0] is smaller. 38 | while len(list1) and len(list2): 39 | if list1[0] < list2[0]: 40 | result.append(list1.pop(0)) 41 | else: 42 | result.append(list2.pop(0)) 43 | 44 | # Now tack on what's left 45 | result.extend(list1) 46 | result.extend(list2) 47 | return result 48 | # LAB(replace solution) 49 | # return 50 | # LAB(end solution) 51 | 52 | # Note: the solution above is kind of cute, but unforunately list.pop(0) 53 | # is not constant time with the standard python list implementation, so 54 | # the above is not strictly linear time. 55 | # An alternate approach uses pop(-1) to remove the endmost elements 56 | # from each list, building a solution list which is backwards. 57 | # Then use reversed() to put the result back in the correct order. That 58 | # solution works in linear time, but is more ugly. 59 | 60 | 61 | # Simple provided test() function used in main() to print 62 | # what each function returns vs. what it's supposed to return. 63 | def test(got, expected): 64 | if got == expected: 65 | prefix = ' OK ' 66 | else: 67 | prefix = ' X ' 68 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 69 | 70 | 71 | # Calls the above functions with interesting inputs. 72 | def main(): 73 | print 'remove_adjacent' 74 | test(remove_adjacent([1, 2, 2, 3]), [1, 2, 3]) 75 | test(remove_adjacent([2, 2, 3, 3, 3]), [2, 3]) 76 | test(remove_adjacent([]), []) 77 | 78 | print 79 | print 'linear_merge' 80 | test(linear_merge(['aa', 'xx', 'zz'], ['bb', 'cc']), 81 | ['aa', 'bb', 'cc', 'xx', 'zz']) 82 | test(linear_merge(['aa', 'xx'], ['bb', 'cc', 'zz']), 83 | ['aa', 'bb', 'cc', 'xx', 'zz']) 84 | test(linear_merge(['aa', 'aa'], ['aa', 'bb', 'bb']), 85 | ['aa', 'aa', 'aa', 'bb', 'bb']) 86 | 87 | 88 | if __name__ == '__main__': 89 | main() 90 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/mimic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | """Mimic pyquick exercise -- optional extra exercise. 10 | Google's Python Class 11 | 12 | Read in the file specified on the command line. 13 | Do a simple split() on whitespace to obtain all the words in the file. 14 | Rather than read the file line by line, it's easier to read 15 | it into one giant string and split it once. 16 | 17 | Build a "mimic" dict that maps each word that appears in the file 18 | to a list of all the words that immediately follow that word in the file. 19 | The list of words can be be in any order and should include 20 | duplicates. So for example the key "and" might have the list 21 | ["then", "best", "then", "after", ...] listing 22 | all the words which came after "and" in the text. 23 | We'll say that the empty string is what comes before 24 | the first word in the file. 25 | 26 | With the mimic dict, it's fairly easy to emit random 27 | text that mimics the original. Print a word, then look 28 | up what words might come next and pick one at random as 29 | the next work. 30 | Use the empty string as the first word to prime things. 31 | If we ever get stuck with a word that is not in the dict, 32 | go back to the empty string to keep things moving. 33 | 34 | Note: the standard python module 'random' includes a 35 | random.choice(list) method which picks a random element 36 | from a non-empty list. 37 | 38 | For fun, feed your program to itself as input. 39 | Could work on getting it to put in linebreaks around 70 40 | columns, so the output looks better. 41 | 42 | """ 43 | 44 | import random 45 | import sys 46 | 47 | 48 | def mimic_dict(filename): 49 | """Returns mimic dict mapping each word to list of words which follow it.""" 50 | # +++your code here+++ 51 | # LAB(begin solution) 52 | mimic_dict = {} 53 | f = open(filename, 'r') 54 | text = f.read() 55 | f.close() 56 | words = text.split() 57 | prev = '' 58 | for word in words: 59 | if not prev in mimic_dict: 60 | mimic_dict[prev] = [word] 61 | else: 62 | mimic_dict[prev].append(word) 63 | # Could write as: mimic_dict[prev] = mimic_dict.get(prev, []) + [word] 64 | # It's one line, but not totally satisfying. 65 | prev = word 66 | return mimic_dict 67 | # LAB(replace solution) 68 | # return 69 | # LAB(end solution) 70 | 71 | 72 | def print_mimic(mimic_dict, word): 73 | """Given mimic dict and start word, prints 200 random words.""" 74 | # +++your code here+++ 75 | # LAB(begin solution) 76 | for unused_i in range(200): 77 | print word, 78 | nexts = mimic_dict.get(word) # Returns None if not found 79 | if not nexts: 80 | nexts = mimic_dict[''] # Fallback to '' if not found 81 | word = random.choice(nexts) 82 | # The 'unused_' prefix turns off the lint warning about the unused variable. 83 | # LAB(replace solution) 84 | # return 85 | # LAB(end solution) 86 | 87 | 88 | # Provided main(), calls mimic_dict() and mimic() 89 | def main(): 90 | if len(sys.argv) != 2: 91 | print 'usage: ./mimic.py file-to-read' 92 | sys.exit(1) 93 | 94 | dict = mimic_dict(sys.argv[1]) 95 | print_mimic(dict, '') 96 | 97 | 98 | if __name__ == '__main__': 99 | main() 100 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/string1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Basic string exercises 10 | # Fill in the code for the functions below. main() is already set up 11 | # to call the functions with a few different inputs, 12 | # printing 'OK' when each function is correct. 13 | # The starter code for each function includes a 'return' 14 | # which is just a placeholder for your code. 15 | # It's ok if you do not complete all the functions, and there 16 | # are some additional functions to try in string2.py. 17 | 18 | 19 | # A. donuts 20 | # Given an int count of a number of donuts, return a string 21 | # of the form 'Number of donuts: ', where is the number 22 | # passed in. However, if the count is 10 or more, then use the word 'many' 23 | # instead of the actual count. 24 | # So donuts(5) returns 'Number of donuts: 5' 25 | # and donuts(23) returns 'Number of donuts: many' 26 | def donuts(count): 27 | # +++your code here+++ 28 | # LAB(begin solution) 29 | if count < 10: 30 | return 'Number of donuts: ' + str(count) 31 | else: 32 | return 'Number of donuts: many' 33 | # LAB(replace solution) 34 | # return 35 | # LAB(end solution) 36 | 37 | 38 | # B. both_ends 39 | # Given a string s, return a string made of the first 2 40 | # and the last 2 chars of the original string, 41 | # so 'spring' yields 'spng'. However, if the string length 42 | # is less than 2, return instead the empty string. 43 | def both_ends(s): 44 | # +++your code here+++ 45 | # LAB(begin solution) 46 | if len(s) < 2: 47 | return '' 48 | first2 = s[0:2] 49 | last2 = s[-2:] 50 | return first2 + last2 51 | # LAB(replace solution) 52 | # return 53 | # LAB(end solution) 54 | 55 | 56 | # C. fix_start 57 | # Given a string s, return a string 58 | # where all occurences of its first char have 59 | # been changed to '*', except do not change 60 | # the first char itself. 61 | # e.g. 'babble' yields 'ba**le' 62 | # Assume that the string is length 1 or more. 63 | # Hint: s.replace(stra, strb) returns a version of string s 64 | # where all instances of stra have been replaced by strb. 65 | def fix_start(s): 66 | # +++your code here+++ 67 | # LAB(begin solution) 68 | front = s[0] 69 | back = s[1:] 70 | fixed_back = back.replace(front, '*') 71 | return front + fixed_back 72 | # LAB(replace solution) 73 | # return 74 | # LAB(end solution) 75 | 76 | 77 | # D. MixUp 78 | # Given strings a and b, return a single string with a and b separated 79 | # by a space ' ', except swap the first 2 chars of each string. 80 | # e.g. 81 | # 'mix', pod' -> 'pox mid' 82 | # 'dog', 'dinner' -> 'dig donner' 83 | # Assume a and b are length 2 or more. 84 | def mix_up(a, b): 85 | # +++your code here+++ 86 | # LAB(begin solution) 87 | a_swapped = b[:2] + a[2:] 88 | b_swapped = a[:2] + b[2:] 89 | return a_swapped + ' ' + b_swapped 90 | # LAB(replace solution) 91 | # return 92 | # LAB(end solution) 93 | 94 | 95 | # Provided simple test() function used in main() to print 96 | # what each function returns vs. what it's supposed to return. 97 | def test(got, expected): 98 | if got == expected: 99 | prefix = ' OK ' 100 | else: 101 | prefix = ' X ' 102 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 103 | 104 | 105 | # Provided main() calls the above functions with interesting inputs, 106 | # using test() to check if each result is correct or not. 107 | def main(): 108 | print 'donuts' 109 | # Each line calls donuts, compares its result to the expected for that call. 110 | test(donuts(4), 'Number of donuts: 4') 111 | test(donuts(9), 'Number of donuts: 9') 112 | test(donuts(10), 'Number of donuts: many') 113 | test(donuts(99), 'Number of donuts: many') 114 | 115 | print 116 | print 'both_ends' 117 | test(both_ends('spring'), 'spng') 118 | test(both_ends('Hello'), 'Helo') 119 | test(both_ends('a'), '') 120 | test(both_ends('xyz'), 'xyyz') 121 | 122 | 123 | print 124 | print 'fix_start' 125 | test(fix_start('babble'), 'ba**le') 126 | test(fix_start('aardvark'), 'a*rdv*rk') 127 | test(fix_start('google'), 'goo*le') 128 | test(fix_start('donut'), 'donut') 129 | 130 | print 131 | print 'mix_up' 132 | test(mix_up('mix', 'pod'), 'pox mid') 133 | test(mix_up('dog', 'dinner'), 'dig donner') 134 | test(mix_up('gnash', 'sport'), 'spash gnort') 135 | test(mix_up('pezzy', 'firm'), 'fizzy perm') 136 | 137 | 138 | # Standard boilerplate to call the main() function. 139 | if __name__ == '__main__': 140 | main() 141 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/string2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.4 -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Additional basic string exercises 10 | 11 | # D. verbing 12 | # Given a string, if its length is at least 3, 13 | # add 'ing' to its end. 14 | # Unless it already ends in 'ing', in which case 15 | # add 'ly' instead. 16 | # If the string length is less than 3, leave it unchanged. 17 | # Return the resulting string. 18 | def verbing(s): 19 | # +++your code here+++ 20 | # LAB(begin solution) 21 | if len(s) >= 3: 22 | if s[-3:] != 'ing': s = s + 'ing' 23 | else: s = s + 'ly' 24 | return s 25 | # LAB(replace solution) 26 | # return 27 | # LAB(end solution) 28 | 29 | 30 | # E. not_bad 31 | # Given a string, find the first appearance of the 32 | # substring 'not' and 'bad'. If the 'bad' follows 33 | # the 'not', replace the whole 'not'...'bad' substring 34 | # with 'good'. 35 | # Return the resulting string. 36 | # So 'This dinner is not that bad!' yields: 37 | # This dinner is good! 38 | def not_bad(s): 39 | # +++your code here+++ 40 | # LAB(begin solution) 41 | n = s.find('not') 42 | b = s.find('bad') 43 | if n != -1 and b != -1 and b > n: 44 | s = s[:n] + 'good' + s[b+3:] 45 | return s 46 | # LAB(replace solution) 47 | # return 48 | # LAB(end solution) 49 | 50 | 51 | # F. front_back 52 | # Consider dividing a string into two halves. 53 | # If the length is even, the front and back halves are the same length. 54 | # If the length is odd, we'll say that the extra char goes in the front half. 55 | # e.g. 'abcde', the front half is 'abc', the back half 'de'. 56 | # Given 2 strings, a and b, return a string of the form 57 | # a-front + b-front + a-back + b-back 58 | def front_back(a, b): 59 | # +++your code here+++ 60 | # LAB(begin solution) 61 | # Figure out the middle position of each string. 62 | a_middle = len(a) / 2 63 | b_middle = len(b) / 2 64 | if len(a) % 2 == 1: # add 1 if length is odd 65 | a_middle = a_middle + 1 66 | if len(b) % 2 == 1: 67 | b_middle = b_middle + 1 68 | return a[:a_middle] + b[:b_middle] + a[a_middle:] + b[b_middle:] 69 | # LAB(replace solution) 70 | # return 71 | # LAB(end solution) 72 | 73 | 74 | # Simple provided test() function used in main() to print 75 | # what each function returns vs. what it's supposed to return. 76 | def test(got, expected): 77 | if got == expected: 78 | prefix = ' OK ' 79 | else: 80 | prefix = ' X ' 81 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 82 | 83 | 84 | # main() calls the above functions with interesting inputs, 85 | # using the above test() to check if the result is correct or not. 86 | def main(): 87 | print 'verbing' 88 | test(verbing('hail'), 'hailing') 89 | test(verbing('swiming'), 'swimingly') 90 | test(verbing('do'), 'do') 91 | 92 | print 93 | print 'not_bad' 94 | test(not_bad('This movie is not so bad'), 'This movie is good') 95 | test(not_bad('This dinner is not that bad!'), 'This dinner is good!') 96 | test(not_bad('This tea is not hot'), 'This tea is not hot') 97 | test(not_bad("It's bad yet not"), "It's bad yet not") 98 | 99 | print 100 | print 'front_back' 101 | test(front_back('abcd', 'xy'), 'abxcdy') 102 | test(front_back('abcde', 'xyz'), 'abcxydez') 103 | test(front_back('Kitten', 'Donut'), 'KitDontenut') 104 | 105 | if __name__ == '__main__': 106 | main() 107 | -------------------------------------------------------------------------------- /google-python-exercises/basic/solution/wordcount.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | """Wordcount exercise 10 | Google's Python class 11 | 12 | The main() below is already defined and complete. It calls print_words() 13 | and print_top() functions which you write. 14 | 15 | 1. For the --count flag, implement a print_words(filename) function that counts 16 | how often each word appears in the text and prints: 17 | word1 count1 18 | word2 count2 19 | ... 20 | 21 | Print the above list in order sorted by word (python will sort punctuation to 22 | come before letters -- that's fine). Store all the words as lowercase, 23 | so 'The' and 'the' count as the same word. 24 | 25 | 2. For the --topcount flag, implement a print_top(filename) which is similar 26 | to print_words() but which prints just the top 20 most common words sorted 27 | so the most common word is first, then the next most common, and so on. 28 | 29 | Use str.split() (no arguments) to split on all whitespace. 30 | 31 | Workflow: don't build the whole program at once. Get it to an intermediate 32 | milestone and print your data structure and sys.exit(0). 33 | When that's working, try for the next milestone. 34 | 35 | Optional: define a helper function to avoid code duplication inside 36 | print_words() and print_top(). 37 | 38 | """ 39 | 40 | import sys 41 | 42 | # +++your code here+++ 43 | # Define print_words(filename) and print_top(filename) functions. 44 | # You could write a helper utility function that reads a file 45 | # and builds and returns a word/count dict for it. 46 | # Then print_words() and print_top() can just call the utility function. 47 | 48 | #### LAB(begin solution) 49 | 50 | def word_count_dict(filename): 51 | """Returns a word/count dict for this filename.""" 52 | # Utility used by count() and Topcount(). 53 | word_count = {} # Map each word to its count 54 | input_file = open(filename, 'r') 55 | for line in input_file: 56 | words = line.split() 57 | for word in words: 58 | word = word.lower() 59 | # Special case if we're seeing this word for the first time. 60 | if not word in word_count: 61 | word_count[word] = 1 62 | else: 63 | word_count[word] = word_count[word] + 1 64 | input_file.close() # Not strictly required, but good form. 65 | return word_count 66 | 67 | 68 | def print_words(filename): 69 | """Prints one per line ' ' sorted by word for the given file.""" 70 | word_count = word_count_dict(filename) 71 | words = sorted(word_count.keys()) 72 | for word in words: 73 | print word, word_count[word] 74 | 75 | 76 | def get_count(word_count_tuple): 77 | """Returns the count from a dict word/count tuple -- used for custom sort.""" 78 | return word_count_tuple[1] 79 | 80 | 81 | def print_top(filename): 82 | """Prints the top count listing for the given file.""" 83 | word_count = word_count_dict(filename) 84 | 85 | # Each item is a (word, count) tuple. 86 | # Sort them so the big counts are first using key=get_count() to extract count. 87 | items = sorted(word_count.items(), key=get_count, reverse=True) 88 | 89 | # Print the first 20 90 | for item in items[:20]: 91 | print item[0], item[1] 92 | 93 | ##### LAB(end solution) 94 | 95 | 96 | # This basic command line argument parsing code is provided and 97 | # calls the print_words() and print_top() functions which you must define. 98 | def main(): 99 | if len(sys.argv) != 3: 100 | print 'usage: ./wordcount.py {--count | --topcount} file' 101 | sys.exit(1) 102 | 103 | option = sys.argv[1] 104 | filename = sys.argv[2] 105 | if option == '--count': 106 | print_words(filename) 107 | elif option == '--topcount': 108 | print_top(filename) 109 | else: 110 | print 'unknown option: ' + option 111 | sys.exit(1) 112 | 113 | if __name__ == '__main__': 114 | main() 115 | -------------------------------------------------------------------------------- /google-python-exercises/basic/string1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Basic string exercises 10 | # Fill in the code for the functions below. main() is already set up 11 | # to call the functions with a few different inputs, 12 | # printing 'OK' when each function is correct. 13 | # The starter code for each function includes a 'return' 14 | # which is just a placeholder for your code. 15 | # It's ok if you do not complete all the functions, and there 16 | # are some additional functions to try in string2.py. 17 | 18 | 19 | # A. donuts 20 | # Given an int count of a number of donuts, return a string 21 | # of the form 'Number of donuts: ', where is the number 22 | # passed in. However, if the count is 10 or more, then use the word 'many' 23 | # instead of the actual count. 24 | # So donuts(5) returns 'Number of donuts: 5' 25 | # and donuts(23) returns 'Number of donuts: many' 26 | def donuts(count): 27 | if count >= 10: 28 | return 'Number of donuts: many' 29 | else: 30 | return 'Number of donuts: %d' % (count) 31 | 32 | 33 | # B. both_ends 34 | # Given a string s, return a string made of the first 2 35 | # and the last 2 chars of the original string, 36 | # so 'spring' yields 'spng'. However, if the string length 37 | # is less than 2, return instead the empty string. 38 | def both_ends(s): 39 | if len(s) > 2: 40 | front = s[:2] 41 | back = s[-2:] 42 | return front + back 43 | else: 44 | return '' 45 | 46 | 47 | # C. fix_start 48 | # Given a string s, return a string 49 | # where all occurences of its first char have 50 | # been changed to '*', except do not change 51 | # the first char itself. 52 | # e.g. 'babble' yields 'ba**le' 53 | # Assume that the string is length 1 or more. 54 | # Hint: s.replace(stra, strb) returns a version of string s 55 | # where all instances of stra have been replaced by strb. 56 | def fix_start(s): 57 | front = s[0] 58 | rest = s[1:] 59 | s.replace(: 60 | return 61 | 62 | 63 | # D. MixUp 64 | # Given strings a and b, return a single string with a and b separated 65 | # by a space ' ', except swap the first 2 chars of each string. 66 | # e.g. 67 | # 'mix', pod' -> 'pox mid' 68 | # 'dog', 'dinner' -> 'dig donner' 69 | # Assume a and b are length 2 or more. 70 | def mix_up(a, b): 71 | # +++your code here+++ 72 | return 73 | 74 | 75 | # Provided simple test() function used in main() to print 76 | # what each function returns vs. what it's supposed to return. 77 | def test(got, expected): 78 | if got == expected: 79 | prefix = ' OK ' 80 | else: 81 | prefix = ' X ' 82 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 83 | 84 | 85 | # Provided main() calls the above functions with interesting inputs, 86 | # using test() to check if each result is correct or not. 87 | def main(): 88 | print 'donuts' 89 | # Each line calls donuts, compares its result to the expected for that call. 90 | test(donuts(4), 'Number of donuts: 4') 91 | test(donuts(9), 'Number of donuts: 9') 92 | test(donuts(10), 'Number of donuts: many') 93 | test(donuts(99), 'Number of donuts: many') 94 | 95 | print 96 | print 'both_ends' 97 | test(both_ends('spring'), 'spng') 98 | test(both_ends('Hello'), 'Helo') 99 | test(both_ends('a'), '') 100 | test(both_ends('xyz'), 'xyyz') 101 | 102 | 103 | print 104 | print 'fix_start' 105 | test(fix_start('babble'), 'ba**le') 106 | test(fix_start('aardvark'), 'a*rdv*rk') 107 | test(fix_start('google'), 'goo*le') 108 | test(fix_start('donut'), 'donut') 109 | 110 | print 111 | print 'mix_up' 112 | test(mix_up('mix', 'pod'), 'pox mid') 113 | test(mix_up('dog', 'dinner'), 'dig donner') 114 | test(mix_up('gnash', 'sport'), 'spash gnort') 115 | test(mix_up('pezzy', 'firm'), 'fizzy perm') 116 | 117 | 118 | # Standard boilerplate to call the main() function. 119 | if __name__ == '__main__': 120 | main() 121 | -------------------------------------------------------------------------------- /google-python-exercises/basic/string2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.4 -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | # Additional basic string exercises 10 | 11 | # D. verbing 12 | # Given a string, if its length is at least 3, 13 | # add 'ing' to its end. 14 | # Unless it already ends in 'ing', in which case 15 | # add 'ly' instead. 16 | # If the string length is less than 3, leave it unchanged. 17 | # Return the resulting string. 18 | def verbing(s): 19 | # +++your code here+++ 20 | return 21 | 22 | 23 | # E. not_bad 24 | # Given a string, find the first appearance of the 25 | # substring 'not' and 'bad'. If the 'bad' follows 26 | # the 'not', replace the whole 'not'...'bad' substring 27 | # with 'good'. 28 | # Return the resulting string. 29 | # So 'This dinner is not that bad!' yields: 30 | # This dinner is good! 31 | def not_bad(s): 32 | # +++your code here+++ 33 | return 34 | 35 | 36 | # F. front_back 37 | # Consider dividing a string into two halves. 38 | # If the length is even, the front and back halves are the same length. 39 | # If the length is odd, we'll say that the extra char goes in the front half. 40 | # e.g. 'abcde', the front half is 'abc', the back half 'de'. 41 | # Given 2 strings, a and b, return a string of the form 42 | # a-front + b-front + a-back + b-back 43 | def front_back(a, b): 44 | # +++your code here+++ 45 | return 46 | 47 | 48 | # Simple provided test() function used in main() to print 49 | # what each function returns vs. what it's supposed to return. 50 | def test(got, expected): 51 | if got == expected: 52 | prefix = ' OK ' 53 | else: 54 | prefix = ' X ' 55 | print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected)) 56 | 57 | 58 | # main() calls the above functions with interesting inputs, 59 | # using the above test() to check if the result is correct or not. 60 | def main(): 61 | print 'verbing' 62 | test(verbing('hail'), 'hailing') 63 | test(verbing('swiming'), 'swimingly') 64 | test(verbing('do'), 'do') 65 | 66 | print 67 | print 'not_bad' 68 | test(not_bad('This movie is not so bad'), 'This movie is good') 69 | test(not_bad('This dinner is not that bad!'), 'This dinner is good!') 70 | test(not_bad('This tea is not hot'), 'This tea is not hot') 71 | test(not_bad("It's bad yet not"), "It's bad yet not") 72 | 73 | print 74 | print 'front_back' 75 | test(front_back('abcd', 'xy'), 'abxcdy') 76 | test(front_back('abcde', 'xyz'), 'abcxydez') 77 | test(front_back('Kitten', 'Donut'), 'KitDontenut') 78 | 79 | if __name__ == '__main__': 80 | main() 81 | -------------------------------------------------------------------------------- /google-python-exercises/basic/wordcount.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | """Wordcount exercise 10 | Google's Python class 11 | 12 | The main() below is already defined and complete. It calls print_words() 13 | and print_top() functions which you write. 14 | 15 | 1. For the --count flag, implement a print_words(filename) function that counts 16 | how often each word appears in the text and prints: 17 | word1 count1 18 | word2 count2 19 | ... 20 | 21 | Print the above list in order sorted by word (python will sort punctuation to 22 | come before letters -- that's fine). Store all the words as lowercase, 23 | so 'The' and 'the' count as the same word. 24 | 25 | 2. For the --topcount flag, implement a print_top(filename) which is similar 26 | to print_words() but which prints just the top 20 most common words sorted 27 | so the most common word is first, then the next most common, and so on. 28 | 29 | Use str.split() (no arguments) to split on all whitespace. 30 | 31 | Workflow: don't build the whole program at once. Get it to an intermediate 32 | milestone and print your data structure and sys.exit(0). 33 | When that's working, try for the next milestone. 34 | 35 | Optional: define a helper function to avoid code duplication inside 36 | print_words() and print_top(). 37 | 38 | """ 39 | 40 | import sys 41 | 42 | # +++your code here+++ 43 | # Define print_words(filename) and print_top(filename) functions. 44 | # You could write a helper utility function that reads a file 45 | # and builds and returns a word/count dict for it. 46 | # Then print_words() and print_top() can just call the utility function. 47 | 48 | ### 49 | 50 | # This basic command line argument parsing code is provided and 51 | # calls the print_words() and print_top() functions which you must define. 52 | def main(): 53 | if len(sys.argv) != 3: 54 | print 'usage: ./wordcount.py {--count | --topcount} file' 55 | sys.exit(1) 56 | 57 | option = sys.argv[1] 58 | filename = sys.argv[2] 59 | if option == '--count': 60 | print_words(filename) 61 | elif option == '--topcount': 62 | print_top(filename) 63 | else: 64 | print 'unknown option: ' + option 65 | sys.exit(1) 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /google-python-exercises/copyspecial/copyspecial.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import sys 10 | import re 11 | import os 12 | import shutil 13 | import commands 14 | 15 | """Copy Special exercise 16 | """ 17 | 18 | # +++your code here+++ 19 | # Write functions and modify main() to call them 20 | 21 | 22 | 23 | def main(): 24 | # This basic command line argument parsing code is provided. 25 | # Add code to call your functions below. 26 | 27 | # Make a list of command line arguments, omitting the [0] element 28 | # which is the script itself. 29 | args = sys.argv[1:] 30 | if not args: 31 | print "usage: [--todir dir][--tozip zipfile] dir [dir ...]"; 32 | sys.exit(1) 33 | 34 | # todir and tozip are either set from command line 35 | # or left as the empty string. 36 | # The args array is left just containing the dirs. 37 | todir = '' 38 | if args[0] == '--todir': 39 | todir = args[1] 40 | del args[0:2] 41 | 42 | tozip = '' 43 | if args[0] == '--tozip': 44 | tozip = args[1] 45 | del args[0:2] 46 | 47 | if len(args) == 0: 48 | print "error: must specify one or more dirs" 49 | sys.exit(1) 50 | 51 | # +++your code here+++ 52 | # Call your functions 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /google-python-exercises/copyspecial/solution/copyspecial.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import sys 10 | import re 11 | import os 12 | import shutil 13 | import commands 14 | 15 | """Copy Special exercise 16 | """ 17 | 18 | # +++your code here+++ 19 | # Write functions and modify main() to call them 20 | 21 | # LAB(begin solution) 22 | def get_special_paths(dirname): 23 | """Given a dirname, returns a list of all its special files.""" 24 | result = [] 25 | paths = os.listdir(dirname) # list of paths in that dir 26 | for fname in paths: 27 | match = re.search(r'__(\w+)__', fname) 28 | if match: 29 | result.append(os.path.abspath(os.path.join(dirname, fname))) 30 | return result 31 | 32 | 33 | def copy_to(paths, to_dir): 34 | """Copy all of the given files to the given dir, creating it if necessary.""" 35 | if not os.path.exists(to_dir): 36 | os.mkdir(to_dir) 37 | for path in paths: 38 | fname = os.path.basename(path) 39 | shutil.copy(path, os.path.join(to_dir, fname)) 40 | # could error out if already exists os.path.exists(): 41 | 42 | 43 | def zip_to(paths, zipfile): 44 | """Zip up all of the given files into a new zip file with the given name.""" 45 | cmd = 'zip -j ' + zipfile + ' ' + ' '.join(paths) 46 | print "Command I'm going to do:" + cmd 47 | (status, output) = commands.getstatusoutput(cmd) 48 | # If command had a problem (status is non-zero), 49 | # print its output to stderr and exit. 50 | if status: 51 | sys.stderr.write(output) 52 | sys.exit(1) 53 | 54 | # LAB(end solution) 55 | 56 | 57 | def main(): 58 | # This basic command line argument parsing code is provided. 59 | # Add code to call your functions below. 60 | 61 | # Make a list of command line arguments, omitting the [0] element 62 | # which is the script itself. 63 | args = sys.argv[1:] 64 | if not args: 65 | print "usage: [--todir dir][--tozip zipfile] dir [dir ...]"; 66 | sys.exit(1) 67 | 68 | # todir and tozip are either set from command line 69 | # or left as the empty string. 70 | # The args array is left just containing the dirs. 71 | todir = '' 72 | if args[0] == '--todir': 73 | todir = args[1] 74 | del args[0:2] 75 | 76 | tozip = '' 77 | if args[0] == '--tozip': 78 | tozip = args[1] 79 | del args[0:2] 80 | 81 | if len(args) == 0: 82 | print "error: must specify one or more dirs" 83 | sys.exit(1) 84 | 85 | # +++your code here+++ 86 | # Call your functions 87 | # LAB(begin solution) 88 | 89 | # Gather all the special files 90 | paths = [] 91 | for dirname in args: 92 | paths.extend(get_special_paths(dirname)) 93 | 94 | if todir: 95 | copy_to(paths, todir) 96 | elif tozip: 97 | zip_to(paths, tozip) 98 | else: 99 | print '\n'.join(paths) 100 | # LAB(end solution) 101 | 102 | if __name__ == "__main__": 103 | main() 104 | -------------------------------------------------------------------------------- /google-python-exercises/copyspecial/xyz__hello__.txt: -------------------------------------------------------------------------------- 1 | Roses are red 2 | Violets are blue 3 | All of my base 4 | Are belong to you! 5 | -------------------------------------------------------------------------------- /google-python-exercises/copyspecial/zz__something__.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/google-python-exercises/copyspecial/zz__something__.jpg -------------------------------------------------------------------------------- /google-python-exercises/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python -tt 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | """A tiny Python program to check that Python is working. 10 | Try running this program from the command line like this: 11 | python hello.py 12 | python hello.py Alice 13 | That should print: 14 | Hello World -or- Hello Alice 15 | Try changing the 'Hello' to 'Howdy' and run again. 16 | Once you have that working, you're ready for class -- you can edit 17 | and run Python code; now you just need to learn Python! 18 | """ 19 | 20 | import sys 21 | 22 | # Define a main() function that prints a little greeting. 23 | def main(): 24 | # Get the name from the command line, using 'World' as a fallback. 25 | if len(sys.argv) >= 2: 26 | name = sys.argv[1] 27 | else: 28 | name = 'World' 29 | print 'Hello', name 30 | 31 | # This is the standard boilerplate that calls the main() function. 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /google-python-exercises/hello.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/google-python-exercises/hello.pyc -------------------------------------------------------------------------------- /google-python-exercises/logpuzzle/animal_code.google.com: -------------------------------------------------------------------------------- 1 | 10.254.254.28 - - [06/Aug/2007:00:12:20 -0700] "GET /keyser/22300/ HTTP/1.0" 302 528 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 2 | 10.254.254.58 - - [06/Aug/2007:00:10:05 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaa.jpg HTTP/1.0" 200 2309 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 3 | 10.254.254.28 - - [06/Aug/2007:00:11:08 -0700] "GET /favicon.ico HTTP/1.0" 302 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 4 | 10.254.254.29 - - [06/Aug/2007:00:13:48 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baag.jpg HTTP/1.0" 302 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com)" 5 | 10.1.40.113 - - [06/Aug/2007:00:11:14 -0700] "GET /keyser/24708/ HTTP/1.0" 200 5694 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 6 | 10.254.254.57 - - [06/Aug/2007:00:13:39 -0700] "GET /keyser/24354/ HTTP/1.0" 404 3404 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 7 | 10.254.254.29 - - [06/Aug/2007:00:05:29 -0700] "GET /keyser/2391/ HTTP/1.0" 302 6267 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 8 | 10.254.254.138 - - [06/Aug/2007:00:13:48 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baac.jpg HTTP/1.0" 200 4284 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6; Google-TR-5.1.707.6657-en) Gecko/20070725 Firefox/2.0.0.6" 9 | 10.254.254.57 - - [06/Aug/2007:00:12:18 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baac.jpg HTTP/1.0" 404 10496 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 10 | 10.254.254.28 - - [06/Aug/2007:00:14:24 -0700] "GET /keyser/22139/ HTTP/1.0" 200 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 11 | 10.254.254.58 - - [06/Aug/2007:00:06:22 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaf.jpg HTTP/1.0" 200 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 12 | 10.254.254.29 - - [06/Aug/2007:00:06:52 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baae.jpg HTTP/1.0" 302 527 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 13 | 10.254.254.37 - - [06/Aug/2007:00:10:05 -0700] "GET /?qdetail=1&qid=1894 HTTP/1.0" 200 1823 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6; Google-TR-5.1.707.6657-en) Gecko/20070725 Firefox/2.0.0.6" 14 | 10.254.254.28 - - [06/Aug/2007:00:12:19 -0700] "GET /baz/js_events/search.js HTTP/1.1" 200 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 15 | 10.1.40.113 - - [06/Aug/2007:00:13:39 -0700] "GET /keyser/24967/ HTTP/1.0" 302 3404 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 16 | 10.1.40.113 - - [06/Aug/2007:00:14:53 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babf.jpg HTTP/1.0" 200 6962 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 17 | 10.254.254.28 - - [06/Aug/2007:00:13:41 -0700] "GET /keyser/24966/ HTTP/1.1" 200 414 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 18 | 10.254.254.138 - - [06/Aug/2007:00:06:22 -0700] "GET /keyser/24727 HTTP/1.1" 302 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com)" 19 | 10.254.254.74 - - [06/Aug/2007:00:12:18 -0700] "GET /keyser/23033/ HTTP/1.0" 302 540 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12" 20 | 10.254.254.28 - - [06/Aug/2007:00:07:21 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babi.jpg HTTP/1.0" 302 306 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1; Google-TR-3) Gecko/20060111 Firefox/1.5.0.1" 21 | 10.254.254.29 - - [06/Aug/2007:00:14:03 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baai.jpg HTTP/1.0" 200 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6; Google-TR-5.1.706.29690-en) Gecko/20070725 Firefox/2.0.0.6" 22 | 10.254.254.66 - - [06/Aug/2007:00:13:40 -0700] "GET /keyser/2298/ HTTP/1.0" 200 4067 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12" 23 | 10.254.254.28 - - [06/Aug/2007:00:05:41 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babf.jpg HTTP/1.0" 302 417 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 24 | 10.254.254.29 - - [06/Aug/2007:00:09:22 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baai.jpg HTTP/1.0" 200 10496 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 25 | 10.254.254.138 - - [06/Aug/2007:00:06:27 -0700] "GET /keyser/23608/ HTTP/1.0" 302 525 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 26 | 10.254.254.138 - - [06/Aug/2007:00:14:00 -0700] "GET /keyser/2past/ HTTP/1.1" 200 6962 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 27 | 10.1.40.113 - - [06/Aug/2007:00:05:31 -0700] "GET /keyser/23403 HTTP/1.0" 200 18124 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 28 | 10.254.254.138 - - [06/Aug/2007:00:14:00 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babg.jpg HTTP/1.0" 302 414 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 29 | 10.254.254.28 - - [06/Aug/2007:00:05:54 -0700] "GET /keyser/24947/ HTTP/1.0" 404 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 30 | 10.254.254.138 - - [06/Aug/2007:00:05:29 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babc.jpg HTTP/1.0" 301 527 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 31 | 10.254.254.138 - - [06/Aug/2007:00:13:41 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babh.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 32 | 10.254.254.29 - - [06/Aug/2007:00:10:03 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babc.jpg HTTP/1.0" 302 1823 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" 33 | 10.254.254.57 - - [06/Aug/2007:00:13:27 -0700] "GET /keyser/24966/ HTTP/1.1" 302 6962 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 34 | 10.254.254.58 - - [06/Aug/2007:00:13:47 -0700] "GET /baz/css/fish.css HTTP/1.1" 302 3404 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 35 | 10.1.40.113 - - [06/Aug/2007:00:11:14 -0700] "GET / HTTP/1.0" 302 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 36 | 10.254.254.28 - - [06/Aug/2007:00:07:05 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babb.jpg HTTP/1.0" 302 1823 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 37 | 10.254.254.137 - - [06/Aug/2007:00:13:41 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babb.jpg HTTP/1.0" 302 12969 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 38 | 10.254.254.28 - - [06/Aug/2007:00:06:22 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babg.jpg HTTP/1.0" 200 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 39 | 10.254.254.66 - - [06/Aug/2007:00:14:53 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baae.jpg HTTP/1.0" 302 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com)" 40 | 10.254.254.28 - - [06/Aug/2007:00:06:17 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babd.jpg HTTP/1.0" 302 525 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 41 | 10.1.40.113 - - [06/Aug/2007:00:13:27 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baba.jpg HTTP/1.0" 302 10496 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 42 | 10.254.254.42 - - [06/Aug/2007:00:10:05 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baab.jpg HTTP/1.0" 200 18124 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 43 | 10.254.254.28 - - [06/Aug/2007:00:13:47 -0700] "GET /favicon.ico HTTP/1.0" 302 306 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 44 | 10.254.254.58 - - [06/Aug/2007:00:05:55 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babd.jpg HTTP/1.0" 200 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 45 | 10.1.40.113 - - [06/Aug/2007:00:12:20 -0700] "GET /keyser/24727 HTTP/1.1" 302 540 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 46 | 10.254.254.58 - - [06/Aug/2007:00:12:18 -0700] "GET /keyser/23072/ HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12" 47 | 10.254.254.138 - - [06/Aug/2007:00:13:47 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baad.jpg HTTP/1.0" 200 540 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 48 | 10.254.254.193 - - [06/Aug/2007:00:12:19 -0700] "GET / HTTP/1.0" 302 414 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 49 | 10.254.254.28 - - [06/Aug/2007:00:14:54 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babj.jpg HTTP/1.0" 200 415 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 50 | 10.254.254.29 - - [06/Aug/2007:00:13:41 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babj.jpg HTTP/1.0" 302 19134 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 51 | 10.254.254.138 - - [06/Aug/2007:00:13:41 -0700] "GET /keyser/24884/ HTTP/1.1" 200 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 52 | 10.254.254.94 - - [06/Aug/2007:00:13:48 -0700] "GET /keyser/247/ HTTP/1.0" 200 3404 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 53 | 10.254.254.138 - - [06/Aug/2007:00:09:49 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baag.jpg HTTP/1.0" 302 3940 "-" "googlebot-mscrawl-moma" 54 | 10.1.40.113 - - [06/Aug/2007:00:12:18 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaf.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1; Google-TR-3) Gecko/20060111 Firefox/1.5.0.1" 55 | 10.254.254.103 - - [06/Aug/2007:00:13:27 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baah.jpg HTTP/1.0" 404 414 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 56 | 10.254.254.28 - - [06/Aug/2007:00:14:26 -0700] "GET /keyser/23367/ HTTP/1.0" 302 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 57 | 10.254.254.28 - - [06/Aug/2007:00:13:47 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaj.jpg HTTP/1.0" 302 414 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 58 | 10.254.254.28 - - [06/Aug/2007:00:05:38 -0700] "GET /baz/img/rss.png HTTP/1.0" 404 3404 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" 59 | 10.254.254.138 - - [06/Aug/2007:00:06:15 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babe.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 60 | 10.254.254.94 - - [06/Aug/2007:00:11:08 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaa.jpg HTTP/1.0" 200 6962 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 61 | 10.254.254.138 - - [06/Aug/2007:00:13:56 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baab.jpg HTTP/1.0" 200 4290 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1" 62 | 10.254.254.193 - - [06/Aug/2007:00:12:19 -0700] "GET /baz/img/powered_by_engedu.png HTTP/1.1" 302 527 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 63 | 10.254.254.28 - - [06/Aug/2007:00:11:08 -0700] "GET /favicon.ico HTTP/1.0" 404 4288 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 64 | 10.254.254.138 - - [06/Aug/2007:00:10:04 -0700] "GET /baz/img/rss.png HTTP/1.1" 200 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 65 | 10.254.254.138 - - [06/Aug/2007:00:12:18 -0700] "GET /?qdetail=1&qid=889 HTTP/1.0" 302 22950 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" 66 | 10.254.254.65 - - [06/Aug/2007:00:05:38 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babe.jpg HTTP/1.0" 302 19124 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 67 | 10.254.254.29 - - [06/Aug/2007:00:09:23 -0700] "GET /keyser/24417/ HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 68 | 10.1.40.113 - - [06/Aug/2007:00:13:48 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baad.jpg HTTP/1.0" 200 540 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 69 | 10.254.254.193 - - [06/Aug/2007:00:11:14 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baah.jpg HTTP/1.0" 200 3404 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 70 | 10.254.254.58 - - [06/Aug/2007:00:06:17 -0700] "GET /favicon.ico HTTP/1.1" 302 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 71 | 10.254.254.28 - - [06/Aug/2007:00:13:40 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babi.jpg HTTP/1.0" 200 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 72 | 10.1.40.113 - - [06/Aug/2007:00:14:53 -0700] "GET /keyser/24535/ HTTP/1.0" 200 402 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 73 | 10.254.254.28 - - [06/Aug/2007:00:06:51 -0700] "GET /keyser/24189/ HTTP/1.0" 301 527 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 74 | 10.254.254.28 - - [06/Aug/2007:00:06:08 -0700] "GET /keyser/24884 HTTP/1.0" 302 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 75 | 10.254.254.38 - - [06/Aug/2007:00:12:18 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baba.jpg HTTP/1.0" 404 7929 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 76 | 10.254.254.138 - - [06/Aug/2007:00:09:49 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-babh.jpg HTTP/1.0" 200 12969 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 77 | 10.1.40.113 - - [06/Aug/2007:00:13:56 -0700] "GET /baz/img/techtalk_logo.png HTTP/1.1" 200 528 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 78 | 10.254.254.138 - - [06/Aug/2007:00:05:31 -0700] "GET /edu/languages/google-python-class/images/puzzle/a-baaj.jpg HTTP/1.0" 302 4067 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 79 | 10.254.254.65 - - [06/Aug/2007:00:13:41 -0700] "GET /favicon.ico HTTP/1.0" 302 3404 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 80 | 10.254.254.28 - - [06/Aug/2007:00:13:48 -0700] "GET /baz/css/fish.css HTTP/1.1" 302 5694 "-" "googlebot-mscrawl-moma (enterprise; bar-XYZ; foo123@google.com,foo123@google.com,foo123@google.com,foo123@google.com)" 81 | -------------------------------------------------------------------------------- /google-python-exercises/logpuzzle/logpuzzle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import os 10 | import re 11 | import sys 12 | import urllib 13 | 14 | """Logpuzzle exercise 15 | Given an apache logfile, find the puzzle urls and download the images. 16 | 17 | Here's what a puzzle url looks like: 18 | 10.254.254.28 - - [06/Aug/2007:00:13:48 -0700] "GET /~foo/puzzle-bar-aaab.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 19 | """ 20 | 21 | 22 | def read_urls(filename): 23 | """Returns a list of the puzzle urls from the given log file, 24 | extracting the hostname from the filename itself. 25 | Screens out duplicate urls and returns the urls sorted into 26 | increasing order.""" 27 | # +++your code here+++ 28 | 29 | 30 | def download_images(img_urls, dest_dir): 31 | """Given the urls already in the correct order, downloads 32 | each image into the given directory. 33 | Gives the images local filenames img0, img1, and so on. 34 | Creates an index.html in the directory 35 | with an img tag to show each local image file. 36 | Creates the directory if necessary. 37 | """ 38 | # +++your code here+++ 39 | 40 | 41 | def main(): 42 | args = sys.argv[1:] 43 | 44 | if not args: 45 | print 'usage: [--todir dir] logfile ' 46 | sys.exit(1) 47 | 48 | todir = '' 49 | if args[0] == '--todir': 50 | todir = args[1] 51 | del args[0:2] 52 | 53 | img_urls = read_urls(args[0]) 54 | 55 | if todir: 56 | download_images(img_urls, todir) 57 | else: 58 | print '\n'.join(img_urls) 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /google-python-exercises/logpuzzle/solution/logpuzzle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2010 Google Inc. 3 | # Licensed under the Apache License, Version 2.0 4 | # http://www.apache.org/licenses/LICENSE-2.0 5 | 6 | # Google's Python Class 7 | # http://code.google.com/edu/languages/google-python-class/ 8 | 9 | import os 10 | import re 11 | import sys 12 | import urllib 13 | 14 | """Logpuzzle exercise 15 | Given an apache logfile, find the puzzle urls and download the images. 16 | 17 | Here's what a puzzle url looks like: 18 | 10.254.254.28 - - [06/Aug/2007:00:13:48 -0700] "GET /~foo/puzzle-bar-aaab.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" 19 | """ 20 | 21 | # LAB(begin solution) 22 | def url_sort_key(url): 23 | """Used to order the urls in increasing order by 2nd word if present.""" 24 | match = re.search(r'-(\w+)-(\w+)\.\w+', url) 25 | if match: 26 | return match.group(2) 27 | else: 28 | return url 29 | # LAB(end solution) 30 | 31 | def read_urls(filename): 32 | """Returns a list of the puzzle urls from the given log file, 33 | extracting the hostname from the filename itself. 34 | Screens out duplicate urls and returns the urls sorted into 35 | increasing order.""" 36 | # +++your code here+++ 37 | # LAB(begin solution) 38 | # Extract the hostname from the filename 39 | underbar = filename.index('_') 40 | host = filename[underbar + 1:] 41 | 42 | # Store the ulrs into a dict to screen out the duplicates 43 | url_dict = {} 44 | 45 | f = open(filename) 46 | for line in f: 47 | # Find the path which is after the GET and surrounded by spaces. 48 | match = re.search(r'"GET (\S+)', line) 49 | # Above uses \S (upper case S) which is any non-space char 50 | # Alternately could use square brackets: "GET ([^ ]+)" 51 | # or the ? form: "GET (.+?) " 52 | 53 | if match: 54 | path = match.group(1) 55 | # Add to dict if it's a special "puzzle" url 56 | # (could combine this 'puzzle' check with the above GET extraction) 57 | if 'puzzle' in path: 58 | url_dict['http://' + host + path] = 1 59 | 60 | return sorted(url_dict.keys(), key=url_sort_key) 61 | # LAB(end solution) 62 | 63 | 64 | def download_images(img_urls, dest_dir): 65 | """Given the urls already in the correct order, downloads 66 | each image into the given directory. 67 | Gives the images local filenames img0, img1, and so on. 68 | Creates an index.html in the directory 69 | with an img tag to show each local image file. 70 | Creates the directory if necessary. 71 | """ 72 | # +++your code here+++ 73 | # LAB(begin solution) 74 | if not os.path.exists(dest_dir): 75 | os.makedirs(dest_dir) 76 | 77 | index = file(os.path.join(dest_dir, 'index.html'), 'w') 78 | index.write('\n') 79 | 80 | i = 0 81 | for img_url in img_urls: 82 | local_name = 'img%d' % i 83 | print 'Retrieving...', img_url 84 | urllib.urlretrieve(img_url, os.path.join(dest_dir, local_name)) 85 | 86 | index.write('' % (local_name,)) 87 | i += 1 88 | 89 | index.write('\n\n') 90 | index.close() 91 | # LAB(end solution) 92 | 93 | 94 | def main(): 95 | args = sys.argv[1:] 96 | 97 | if not args: 98 | print 'usage: [--todir dir] logfile ' 99 | sys.exit(1) 100 | 101 | todir = '' 102 | if args[0] == '--todir': 103 | todir = args[1] 104 | del args[0:2] 105 | 106 | img_urls = read_urls(args[0]) 107 | 108 | if todir: 109 | download_images(img_urls, todir) 110 | else: 111 | print '\n'.join(img_urls) 112 | 113 | if __name__ == '__main__': 114 | main() 115 | -------------------------------------------------------------------------------- /gui.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # We need to: access an external process; do easy 3 | # string substitution; and show a GUI. These three 4 | # modules provide such functionality. 5 | import commands, re, Tkinter 6 | 7 | # Every second--one thousand milliseconds--this function 8 | # gets the latest 'uptime' result, displays it, then 9 | # reschedules itself for the next cycle. 10 | def one_update(): 11 | # This just collects the result of the external 12 | # built-in 'uptime' command. 13 | result = commands.getoutput("uptime") 14 | 15 | # Discard everything in the result string that 16 | # appears before the load averages themselves. 17 | pattern = ".*load averages*: " 18 | display_text.set(re.sub(pattern, "", result)) 19 | 20 | # Do it again another second later. 21 | label.after(1000, one_update) 22 | 23 | root = Tkinter.Tk() 24 | # Create a display "buffer". 25 | display_text = Tkinter.StringVar() 26 | 27 | # Create a GUI widget which shows the results. 28 | label = Tkinter.Label(root, textvariable = display_text, width = 20) 29 | 30 | # Place the Label in the main window. 31 | label.pack() 32 | 33 | # Begin the measurements. 34 | one_update() 35 | 36 | # Start processing events, that is, turn the GUI "on". 37 | root.mainloop() 38 | 39 | -------------------------------------------------------------------------------- /gui2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import oogui 5 | 6 | _GUI_TYPES = ('Tkinter', 7 | 'WxPy', 8 | 'PyQt', 9 | 'PyGtk', 10 | 'FXPy') 11 | 12 | _BUTTON_LABEL = 'Push Me' 13 | _TITLE = 'Python GUI Basics Example' 14 | _BORDER_WIDTH = 10 15 | 16 | -------------------------------------------------------------------------------- /ifelse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # new comment 4 | 5 | import os 6 | 7 | print "/tmp is a directory" 8 | else: 9 | print "/tmp is not a directoy" 10 | -------------------------------------------------------------------------------- /import.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import module 5 | -------------------------------------------------------------------------------- /isfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | if os.path.isfile("/etc/passwd"): 6 | print "passwd is a file" 7 | else: 8 | print "passwd is not a file" 9 | -------------------------------------------------------------------------------- /log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | try: 4 | import sys 5 | 6 | logfile = open('/tmp/mylog.txt', 'a') 7 | print >> logfile, 'Fatal error: invalid input!' 8 | logfile.close() 9 | 10 | except: 11 | print 'Could not pull this off' 12 | -------------------------------------------------------------------------------- /makepass.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # THIS IS A COMMENT 4 | 5 | 6 | from random import choice 7 | 8 | import string 9 | 10 | def GenPasswd(length=8, chars=string.letters+string.digits): 11 | return ''.join([ choice(chars) for i in range(length) ]) 12 | -------------------------------------------------------------------------------- /makepass.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/makepass.pyc -------------------------------------------------------------------------------- /module.py: -------------------------------------------------------------------------------- 1 | #Very short script that reuses pysysinfo_func_2 code 2 | 3 | from pysysinfo_func_2 import disk_func 4 | import subprocess 5 | 6 | def tmp_space(): 7 | tmp_usage = "du" 8 | tmp_arg = "-h" 9 | path = "/tmp" 10 | print "Space used in /tmp directory" 11 | subprocess.call([tmp_usage, tmp_arg, path]) 12 | 13 | def main(): 14 | disk_func() 15 | tmp_space() 16 | 17 | if __name__ == "__main__": 18 | main() 19 | -------------------------------------------------------------------------------- /my_new_module: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | -------------------------------------------------------------------------------- /my_restore.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This is 'my_restore.py'. Invoke it as, for example, 4 | # my_restore.py my_source.c 5 | # to show all the archived files named 'my_source.c' 6 | # which the user can select for retrieval. 7 | 8 | 9 | import os,sys,Tkinter 10 | 11 | pattern = sys.argv[1] 12 | archive = '/dev/nrtape' 13 | 14 | def esf(): 15 | # Construct the string which lists all selected files, 16 | # separated by a single blank. Use that string to 17 | # specify the exact listof files to extract from the 18 | # archive. 19 | command = 'tar xf %s %s' % (archive, 20 | ' '.join([lb.get(index) for index in lb.curselection()])) 21 | os.system(command) 22 | 23 | # MULTIPLE so that we can select and extract several files in a 24 | # single operation. 25 | lb = Tkinter.Listbox(height = 12, width = 30, selectmode = Tkinter.MULTIPLE) 26 | lb.pack() 27 | Tkinter.Button(text = "Extract selected files", command = esf).pack() 28 | 29 | # The "[:-1]" says, "ignore the trailing newline tar emits". 30 | for qualified_name in \ 31 | os.popen('tar tf %s' % archive).read().split('\n')[:-1]: 32 | # Does the basename of this item match the pattern? 33 | if os.path.basename(qualified_name).count(pattern) > 0: 34 | lb.insert(Tkinter.END, qualified_name) 35 | 36 | # Show the GUI panel. 37 | Tkinter.mainloop() 38 | -------------------------------------------------------------------------------- /new_pysysinfo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # short script that uses code from pysysinfo.py 4 | 5 | from pysysinfo import diskspacer 6 | import subprocess 7 | 8 | def tmp_space(): 9 | tmp_usage = "du" 10 | tmp_arg = "-h" 11 | path = "/tmp" 12 | print "\nSpace used in /tmp directory" 13 | subprocess.call([tmp_usage, tmp_arg, path]) 14 | 15 | def main(): 16 | diskspacer() 17 | tmp_space() 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /nfl_team_pick.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import random, sys, os, commands 4 | 5 | teams = ["Bills", "Dolphins", "Patriots", "Jets", "Ravens", "Bengals", "Browns", "Steelers", "Texans", "Colts", "Jaguars", "Titans", "Broncos", "Chiefs", "Raiders", "Chargers", "Cowboys", "Jets", "Eagles", "Redskins", "Bears", "Lions", "Packers", "Vikings", "Falcons", "Panthers", "Saints", "Buccaneers", "Cardinals", "Rams", "49ers", "Seahawks"] 6 | 7 | #print Your getoutputstatus(date) team pick is random.choice(teams) 8 | print random.choice(teams) 9 | 10 | -------------------------------------------------------------------------------- /openfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # open file 4 | 5 | with open("/tmp/foo.txt", "r") as f: 6 | lines = f.readlines() 7 | print lines 8 | #print f 9 | 10 | -------------------------------------------------------------------------------- /prac.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # this is a comment 4 | 5 | def main() : 6 | t = raw_input("Your entry here: ") 7 | print 'Your string is %s!' % t 8 | print "The first letter of your string is: %s" % t[0] 9 | print "The last letter of your string is: %s" % t[-1] 10 | print "Your string in upper: %s" % t.upper() 11 | print "Your string in lower: %s" % t.lower() 12 | print "Your string in title form: %s" % t.title() 13 | print "Here is your string split: %s" % t.split() 14 | print "Here is your string tabbed: %s" % '\t'.join(t) 15 | print "Here is your string joined: %s" % ''.join(t) 16 | print "Here is your string replaced: %s" % t.replace("This", "That") 17 | 18 | if __name__ == "__main__": 19 | main() 20 | -------------------------------------------------------------------------------- /pyls.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | #Python wrapper for the ls command 4 | 5 | import subprocess 6 | 7 | subprocess.call(["ls","-l"]) 8 | -------------------------------------------------------------------------------- /pysysinfo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #A System Information Gathering Script 4 | 5 | import subprocess 6 | 7 | def namer(): 8 | print __name__ 9 | 10 | #Command 1 11 | def unamer(): 12 | uname = "uname" 13 | uname_arg = "-a" 14 | print "Gathering system information with %s command:\n" % uname 15 | subprocess.call([uname, uname_arg]) 16 | 17 | #Command 2 18 | def diskspacer(): 19 | diskspace = "df" 20 | diskspace_arg = "-h" 21 | print "Gathering diskspace information %s command:\n" % diskspace 22 | subprocess.call([diskspace, diskspace_arg]) 23 | 24 | def main(): 25 | unamer() 26 | diskspacer() 27 | 28 | #main() 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /rib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/rib -------------------------------------------------------------------------------- /socket.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import socket 4 | import re 5 | import sys 6 | 7 | def check_server(address, port): 8 | ''' 9 | create a TCP socket 10 | ''' 11 | s = socket.socket() 12 | print "Attempting to connect to %s on port %s" % (address, port) 13 | try: 14 | s.connect((address, port)) 15 | print "Connected to %s on port %s" % (address, port) 16 | return True 17 | except socket.error, e: 18 | print "Connection to %s on port %s failed: %s" % (address, port, e) 19 | return False 20 | 21 | if __name__ == '__main__': 22 | from optparse import OptionParser 23 | parser = OptionParser() 24 | 25 | parser.add_option("-a", "--address", dest="address", default='localhost', 26 | help="ADDRESS for server", metavar="ADDRESS") 27 | 28 | parser.add_option("-p", "--port", dest="port", type="int", default=80, 29 | help="PORT for server", metavar="PORT") 30 | 31 | (options, args) = parser.parse_args() 32 | print 'options: %s, args: %s' % (options, args) 33 | check = check_server(options.address, options.port) 34 | print 'check_server returned %s' % check 35 | sys.exit(not check) 36 | 37 | -------------------------------------------------------------------------------- /socket.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barnzdan/python/b29594eb191f71519ca2c909fc030385ec033112/socket.pyc -------------------------------------------------------------------------------- /test_func.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | def pyfunc(): 4 | print "Hello function" 5 | 6 | 7 | pyfunc() 8 | 9 | for i in range(50): 10 | pyfunc() 11 | -------------------------------------------------------------------------------- /test_func2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | def print_many(): 5 | print "Hello fuction" 6 | print "Hi again function" 7 | print "Sick of me yet?" 8 | 9 | print_many() 10 | 11 | 12 | 13 | def addition(): 14 | sum = 1+1 15 | print "1 + 1 = %s" % sum 16 | 17 | 18 | addition() 19 | -------------------------------------------------------------------------------- /testssh.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import subprocess 4 | 5 | proc = subprocess.Popen([ 'ssh', 'dlb@172.16.1.6'], 'cat > %s' % filename ], 6 | stdin = subprocess.PIPE) 7 | proc.communicate(file_contents) 8 | if proc.retcode != 0: 9 | print 'We have a problem' 10 | sys.exit(1) 11 | -------------------------------------------------------------------------------- /tryex1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | user_input = raw_input("Enter an integer ") 4 | try: 5 | number = int(user_input) 6 | print "You entered", number 7 | except ValueError: 8 | print "intergers, please!" 9 | -------------------------------------------------------------------------------- /tutorial.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # 4 | # dlb 5 | # 6 | 7 | import sys 8 | 9 | print 'Hello', sys.argv[1] 10 | 11 | -------------------------------------------------------------------------------- /url_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | """ 5 | 1. It takes arguments for: timeout, url, expected_response_code, retry_count 6 | 2. The script performs an HTTP GET for the url 7 | 3. If the HTTP response code matches the expected_response_code the script will exit with status code 0 8 | 4. If the the HTTP GET either times out or the HTTP response code doesn't match, retry until retry count is exhausted 9 | 5. If the retry count is exhausted without receiving the expected_response_code, print an error message to STDERR and exit with a non zero status code. 10 | """ 11 | 12 | import os, sys, httplib, socket 13 | 14 | # 15 | # verify number of arguments 16 | # 17 | args = len(sys.argv) 18 | if not args == 5: 19 | print "Usage: %s {timeout|url|expected_ response|retry_count}" % \ 20 | os.path.basename(sys.argv[0]) 21 | sys.exit(1) 22 | 23 | # 24 | # redirect stderr to null class 25 | # 26 | class NullWriter: 27 | def write(self, s): 28 | pass 29 | 30 | sys.stderr = NullWriter() 31 | 32 | # 33 | # assign the args 34 | # 35 | TimeOut = (sys.argv[1]) 36 | site = (sys.argv[2]) 37 | ExpectResponse = (sys.argv[3]) 38 | RetryCount = (sys.argv[4]) 39 | 40 | # 41 | # connect 42 | # 43 | i = 0 44 | t = int(RetryCount) 45 | while i < t: 46 | c = str(t - i) 47 | ConnectString = httplib.HTTPConnection(site, 80, TimeOut) 48 | ConnectString.request("GET", "/") 49 | Response = ConnectString.getresponse() 50 | sock = socket.socket() 51 | sock.settimeout(8.2) 52 | ConnectString.close() 53 | if Response.status == httplib.OK: 54 | print "URL is OK" 55 | sys.exit(0) 56 | else: 57 | print "URL did not connect as expected." 58 | print "Will attempt the connection " + c + " more times." 59 | i += 1 60 | sys.exit(1) 61 | --------------------------------------------------------------------------------