Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> interactive_add_to_phone_book() Traceback (most recent call last): File "", line 1, in interactive_add_to_phone_book() NameError: name 'interactive_add_to_phone_book' is not defined >>> interactive_add_to_phonebook() Enter New Contact: Fred Enter New Phone Number: 212-222-2222 >>> interactive_add_to_phonebook() Enter New Contact: Pizza Palace Enter New Phone Number: 246-8902 >>> ================================ RESTART ================================ >>> >>> os.getcwd() '/Users/adam/Desktop/Summer 2011 Scripts' >>> interactive_add_to_phonebook() Enter New Contact: Fred Enter New Phone Number: 212-222-2222 >>> interactive_add_to_phonebook() Enter New Contact: Pizza Pallace Enter New Phone Number: 246-8902 >>> put_phonebook_in_file('phonebook_001.txt') >>> ================================ RESTART ================================ >>> >>> get_phonebook_in_file('phonebook_001.txt') Traceback (most recent call last): File "", line 1, in get_phonebook_in_file('phonebook_001.txt') NameError: name 'get_phonebook_in_file' is not defined >>> get_phonebook_from_file('phonebook_001.txt') >>> my_phonebook {'Fred': '212-222-2227\n', 'John': '212-123-4567\n', 'Fido': '203-449-7777\n', 'Mary': '212-777-1237\n', 'Pizza Pallace': '246-8902\n'} >>> ================================ RESTART ================================ >>> >>> get_phonebook_from_file('phonebook_001.txt') >>> my_phonebook {'Fred': '212-222-2227', 'John': '212-123-4567', 'Fido': '203-449-7777', 'Mary': '212-777-1237', 'Pizza Pallace': '246-8902'} >>> 'Fred,212-222-2227'.split(',') ['Fred', '212-222-2227'] >>> 5//2 2 >>> 5.0//2 2.0 >>> 5.1//2.5 2.0 >>> if True or False: print('hello') hello >>> if False or False: print('hello') >>> if False or 2: print('hello') hello >>> Node or 0 Traceback (most recent call last): File "", line 1, in Node or 0 NameError: name 'Node' is not defined >>> None or 0 0 >>> if 0: print('hello') >>> if None: print('hello') >>> if 0 or 1: print('hello') hello >>> import re >>> if re.search('abc','adfkjjkabc'): print('hello') hello >>> re.search('abc','adfkjjkabc') <_sre.SRE_Match object at 0x15fb2f8> >>> if re.search('abc','adddddc'): print('hello') >>> re.search('abc','addddc') >>> re.search('abc','addddc') == None True >>> output = 7 >>> output 7 >>> if output = 2 or 3 or 4: SyntaxError: invalid syntax >>> if output == 2 or 3 or 4: print('hello') hello >>> if (output == 2) or 3 or 4: print('hello') hello >>> if (output == 2) or (output == 3) or (output == 4): print('hello') >>> if output == (2 or 3 or 4): print('hello') >>> output 7 >>> if output == (2 or 7 or 4): print('hello') >>> (2 or 7 or 4) 2 >>> re.search('abc','adaaac') >>> output = re.search('abc','adaaac') >>> output >>> type(output) >>> 'hello'[0] 'h' >>> 'hello'[1] 'e' >>> 'hello'[5-1] 'o' >>> 'hello'[-1] 'o' >>> 'hello'[-5] 'h' >>> 'hello'[1:3] 'el' >>> 'hello'[-4:3] 'el' >>> 'hello'[-4:-2] 'el' >>> '' '' >>> len('') 0 >>> len('a') 1 >>> 'Fred,size 10, 150 pounds, 5\' 11\"' 'Fred,size 10, 150 pounds, 5\' 11"' >>> 'Fred,size 10, 150 pounds, 5\' 11\"'.split(',') ['Fred', 'size 10', ' 150 pounds', ' 5\' 11"'] >>> 'Fred|size 10| 150 pounds| 5\' 11\"'.split('|') ['Fred', 'size 10', ' 150 pounds', ' 5\' 11"'] >>> output = re.search'('Abby','Where is Abby in this string?') SyntaxError: invalid syntax >>> output = re.search('Abby','Where is Abby in this string?') >>> output <_sre.SRE_Match object at 0x15fb2f8> >>> my_string = 'Where is Abby in this string?' >>> my_string 'Where is Abby in this string?' >>> output <_sre.SRE_Match object at 0x15fb2f8> >>> output.start() 9 >>> output.end() 13 >>> output.group() 'Abby' >>> my_string[output.start():output.end()] 'Abby' >>> output = re.search('[^Dd]og','Is it a dog or a hog?') >>> output.group() 'hog' >>> output = re.search('Dog.*Dog','Here Dogggy, Doggy') >>> output.group() 'Dogggy, Dog' >>> output = re.search('ing.*gy','He is finding my doggy') >>> output.group() 'ing my doggy' >>> re.search('[\.?!]$','Where is my dog?') <_sre.SRE_Match object at 0x15fb2f8> >>> re.search('[\.?!]$','That is that.') <_sre.SRE_Match object at 0x15fb3a0> >>> re.search('[\.?!]$','That is that!') <_sre.SRE_Match object at 0x15fb2f8> >>> re.search('[\.?!]$','That is that') >>> output = re.search('(abc)+','abcabcefg') >>> output.group() 'abcabc' >>> output = re.search('(abc)*','abcabcefg') >>> output.group() 'abcabc' >>> output = re.search('(abc)*','efg') >>> outout Traceback (most recent call last): File "", line 1, in outout NameError: name 'outout' is not defined >>> output.group() '' >>> output = re.search('(abc)+','efg') >>> output >>> output = re.search('abc(abc)*','efg') >>> output >>> my_list = [5,6,7,'apple'] >>> my_list[2] = 'pear' >>> my_list [5, 6, 'pear', 'apple'] >>> my_list.index('pear') 2 >>> my_list.count('pear') 1 >>> my_list.append('cat') >>> my_list.extend(['dog','gerbil']) >>> my_list [5, 6, 'pear', 'apple', 'cat', 'dog', 'gerbil'] >>> my_list.pop(0) 5 >>> my_list [6, 'pear', 'apple', 'cat', 'dog', 'gerbil'] >>> my_list(1) Traceback (most recent call last): File "", line 1, in my_list(1) TypeError: 'list' object is not callable >>> my_list.pop(1) 'pear' >>> my_list [6, 'apple', 'cat', 'dog', 'gerbil'] >>> my_list.pop(0) 6 >>> my_list ['apple', 'cat', 'dog', 'gerbil'] >>> my_list[0] = 'fish; SyntaxError: EOL while scanning string literal >>> my_list[0] = 'fish' >>> my_list.append['anaconda'] Traceback (most recent call last): File "", line 1, in my_list.append['anaconda'] TypeError: 'builtin_function_or_method' object is not subscriptable >>> my_list.append('anaconda') >>> my_list ['fish', 'cat', 'dog', 'gerbil', 'anaconda'] >>> my_list.sort() >>> my_list ['anaconda', 'cat', 'dog', 'fish', 'gerbil'] >>> colors = {} >>> colors['apple'] = 'red' >>> colors['chicken'] = 'yellow' >>> colors['sky'] = 'blue' >>> colors {'chicken': 'yellow', 'sky': 'blue', 'apple': 'red'} >>> colors['chicken'] 'yellow' >>> 'chicken' in colors True >>> 'cat' in colors False >>> 'cat' in ['mouse','cat'] True >>> for item in colors: print(item+':',colors[item]) chicken: yellow sky: blue apple: red >>> colors.keys() dict_keys(['chicken', 'sky', 'apple']) >>> list(colors.keys()) ['chicken', 'sky', 'apple'] >>> my_keys = list(colors.keys()) >>> my_keys ['chicken', 'sky', 'apple'] >>> my_keys.sort() >>> my_keys ['apple', 'chicken', 'sky'] >>> for item in my_keys: print(item+':',colors[item]) apple: red chicken: yellow sky: blue >>> colors.keys() dict_keys(['chicken', 'sky', 'apple']) >>> colors.values() dict_values(['yellow', 'blue', 'red']) >>> colors.items() dict_items([('chicken', 'yellow'), ('sky', 'blue'), ('apple', 'red')]) >>> list(colors.items()) [('chicken', 'yellow'), ('sky', 'blue'), ('apple', 'red')] >>>