Dictionaries & Sets

[Pages:72]+

Dictionaries & Sets

Introduction to Programming - Python

+ Agenda

Week of 4/19

n Days 19 ? Class Notes ? Posted n Reading: Gaddis ? Chapter 9 n Final Exam ? Monday, May 16th, 6 ? 7:50 PM n Dictionaries n Sets n Object Serialization

+

Altimeter Chart for Ingenuity's First Flight



+

Review

+ Unpacking Strings to Lists

input_string = """Name,Phone,Address Mike Smith,15554218841,123 Nice St, Roy, NM, USA Anita Hernandez,15557789941,425 Sunny St, New York, NY, USA Guido van Rossum,315558730,Science Park 123, 1098 XG Amsterdam, NL"""

def get_phone_info(str2_unsplit): # input: string of names, phone nos. and addresses # get name and phone number of each person # output: list of lists of people and phone numbers results = [] # get the first name and phone number # what goes into the for loop? for line in ... : # how do we get only the name and phone number? results.append(...) return results

print(get_phone_info(input_string))

+

+

+ Reading Data from Files

""" Imagine file contents in 'philosophers.txt': 'John Locke\nDavid Hume\nEdmund Burke\n' """ philosophers_file = open('philosophers.txt') # read each line and print the philosopher's name philosophers_file.close()

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download