diff --git a/advanced-iterators.html b/advanced-iterators.html index f299960..fce7dc8 100644 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -295,7 +295,7 @@ StopIteration 'Chris', 'Ethan', 'Sarah', 'Lizzie', 'Wesley']
  1. This idiom returns a list of the lines in a text file. -
  2. Unfortunately (for this example), the list(open(filename)) idiom also includes the carriage returns at the end of each line. This list comprehension uses the rstrip() string method to strip trailing whitespace from each line. +
  3. Unfortunately (for this example), the list(open(filename)) idiom also includes the carriage returns at the end of each line. This list comprehension uses the rstrip() string method to strip trailing whitespace from each line. (Strings also have an lstrip() method to strip leading whitespace, and a strip() method which strips both.)
  4. The sorted() function takes a list and returns it sorted. By default, it sorts alphabetically.
  5. But the sorted() function can also take a function as the key parameter, and it sorts by that key. In this case, the sort function is len(), so it sorts by len(each item). Shorter names come first, then longer, then longest.