Read through section 10.8 of the book and do the examples.
Now we have the tools to write a modifier version of only_upper from 10.7:
def remove_non_upper(strings): """Removes the elements from a list of strings that aren't in all uppercase characters.""" i = 0 #this is a while loop because we don't always increment the index while i < len(strings): string = strings[i] if string.isupper(): #string is uppercase, move to the next one i += 1 else: #string has lowercase characters, delete it! del strings[i]
Now we can test out the two versions: (You need to have the 10.7's only_upper as well.)
>>> names = ['JARAD', 'Madeline', 'JANET', 'BILL', 'Harold'] >>> uppers = only_upper(names) >>> uppers ['JARAD', 'JANET', 'BILL'] >>> names ['JARAD', 'Madeline', 'JANET', 'BILL', 'Harold'] >>> remove_non_upper(names) >>> names ['JARAD', 'JANET', 'BILL'] >>>
Now read through section 10.9 of the book and do the examples. What I mostly want you to get from this is that there are neat things you can do to easily change strings to lists and vice-versa.
Read through sections 10.10, 10.11, and 10.12 of the book and do the examples (3 pages in total, sorry).
I also recommend looking at 10.13 to get an idea of some common mistakes with lists and references.