Whitespace corrections, a couple bug fixes, replacing a format string with constructi...
[wordplay-cdsw-solutions] / solution_6.py
index e4d7b3e25aa350dc704e0aa99239b136b17bf458..62e13f2d0731c38c9840e6d8fea1fea0e2e62e8d 100644 (file)
@@ -1,13 +1,11 @@
 import scrabble
 
-
-# Print hte longest word where every digit is unique.
+# Print the longest word where every character is unique.
 # I use a double loop in this. Note that I also re-use my "longest word" logic
 # from the easy solution to (2).
 
 # See the advanced solution for a shorter way to do this.
 
-
 new_words = []
 for word in scrabble.wordlist:
     local_chars = {}
@@ -16,18 +14,17 @@ for word in scrabble.wordlist:
         # have we seen this character before?
         if character in local_chars:
             seen_before = True
-            break
+            break # Exit the loop early, since we've found a collision.
         # store the character
         local_chars[character] = 1
-    
+
     if not seen_before:
         new_words.append(word)
-            
-# Reuse my code for longest
+
+# Reuse my code for longest word
 longest_so_far = ''
 for word in new_words:
     if len(word) > len(longest_so_far):
         longest_so_far = word
-        
-print longest_so_far
 
+print longest_so_far

Benjamin Mako Hill || Want to submit a patch?