Page 188 -
P. 188
sanitized for your protection
Let’s write the code to convert your existing data into a sanitized version of itself. You were to
create four new lists to hold the sanitized data. You were then to iterate over each athlete’s data
and append each sanitized string from each list to an appropriate new list. You were to conclude
your program by printing a sorted copy of each new list to the screen.
with open('james.txt') as jaf: data = jaf.readline()
james = data.strip().split(',')
with open('julie.txt') as juf: data = juf.readline()
julie = data.strip().split(',')
with open('mikey.txt') as mif: data = mif.readline()
mikey = data.strip().split(',')
with open('sarah.txt') as saf: data = saf.readline()
sarah = data.strip().split(',')
clean_james = []
Create four clean_julie = []
new, initially
empty lists. clean_mikey = []
clean_sarah = []
for each_t in james:
clean_james.append(sanitize(each_t))
for each_t in julie:
clean_julie.append(sanitize(each_t)) T ake each of the data items in
for each_t in mikey: the original lists, sanitize them,
and then append the sanitized
clean_mikey.append(sanitize(each_t)) data to the appropriate new
for each_t in sarah: list.
clean_sarah.append(sanitize(each_t))
The four “print()”
sorted(clean_james)
statements now print( )
display the new sorted(clean_julie)
lists, which are print( )
sorted(clean_mikey)
sorted, too. print( )
sorted(clean_sarah)
print( )
152 Chapter 5