From 8e7741fdb40f145744421cf8b136bbacf6aa4736 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 27 Aug 2009 15:14:27 -0400 Subject: [PATCH] mismatch between example and first footnote in #unique-items --- advanced-iterators.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced-iterators.html b/advanced-iterators.html index cd585dd..b0922b5 100755 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -142,7 +142,7 @@ if __name__ == '__main__': >>> set(''.join(words)) {'E', 'D', 'M', 'O', 'N', 'S', 'R', 'Y'}
    -
  1. Given a list of several strings, the set() function will return a set of unique strings from the list. This makes sense if you think of it like a for loop. Take the first item from the list, put it in the set. Second. Third. Fourth — wait, that’s in the set already, so it only gets listed once, because Python sets don’t allow duplicates. Fifth. Sixth — again, a duplicate, so it only gets listed once. The end result? All the unique items in the original list, without any duplicates. The original list doesn’t even need to be sorted first. +
  2. Given a list of several strings, the set() function will return a set of unique strings from the list. This makes sense if you think of it like a for loop. Take the first item from the list, put it in the set. Second. Third. Fourth. Fifth — wait, that’s in the set already, so it only gets listed once, because Python sets don’t allow duplicates. Sixth. Seventh — again, a duplicate, so it only gets listed once. The end result? All the unique items in the original list, without any duplicates. The original list doesn’t even need to be sorted first.
  3. The same technique works with strings, since a string is just a sequence of characters.
  4. Given a list of strings, ''.join(a_list) concatenates all the strings together into one.
  5. So, given a list of strings, this line of code returns all the unique characters across all the strings, with no duplicates.