From 7cb91f9747041cfab810229c8c50f31f7f3e540f Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 15 Jul 2009 12:52:12 -0400 Subject: [PATCH] added note about dictionary comprehensions --- advanced-iterators.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced-iterators.html b/advanced-iterators.html index 5487223..20271f5 100755 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -407,7 +407,7 @@ Wesley 'N': '5', 'S': '1', 'R': '6', 'Y': '7'}
  1. Given a list of letters and a list of digits (each represented here as 1-character strings), the zip function will create a pairing of letters and digits, in order. -
  2. Why is that cool? Because that data structure happens to be exactly the right structure to pass to the dict() function to create a dictionary that uses letters as keys and their associated digits as values. Although the printed representation of the dictionary lists the pairs in a different order (dictionaries have no “order” per se), you can see that each letter is associated with the digit, based on the ordering of the original characters and guess sequences. +
  3. Why is that cool? Because that data structure happens to be exactly the right structure to pass to the dict() function to create a dictionary that uses letters as keys and their associated digits as values. (This isn’t the only way to do it, of course. You could use a dictionary comprehension [FIXME xref] to create the dictionary directly.) Although the printed representation of the dictionary lists the pairs in a different order (dictionaries have no “order” per se), you can see that each letter is associated with the digit, based on the ordering of the original characters and guess sequences.

The alphametics solver uses this technique to create a dictionary that maps letters in the puzzle to digits in the solution, for each possible solution.