X-Git-Url: https://projects.mako.cc/source/wordplay-cdsw-solutions/blobdiff_plain/4e09563052459f99272cfee99d44f8a9abce85cb..d57af8e41dd0a0a46fc411ad2488d029244921e1:/solution_6_advanced.py diff --git a/solution_6_advanced.py b/solution_6_advanced.py index 24927ad..5db3920 100644 --- a/solution_6_advanced.py +++ b/solution_6_advanced.py @@ -1,25 +1,21 @@ import scrabble - -# Print the longest word where every digit is unique. +# Print the longest word where every character is unique. # I used a Set for this. Don't worry: you didn't miss anything if you don't know # what a set is. We didn't teach it, but if you are reading this, you get a bonus! - # A set is a container like a list or a dict, except that *each element can be stored only once*. # Think of it like the keys of a dict, except there isn't any value associated with each key. # I use Sets to count digits below. Feel free to look up the Set online and try it in the # interpreter. - new_words = [] for word in scrabble.wordlist: local_chars = {} - if len(word) == len(set(word)): # Wait what!? See if you can figure out why this works. - new_words.append(word) - + if len(word) == len(set(word)): # Wait what!? See if you can figure out why this works. + new_words.append(word) -# Reuse my code for longest (in this case, the code to track all occurences, from the +# Reuse my code for longest word, (in this case, the code to track all occurences) from the # advanced solution. longest_so_far = [] @@ -27,8 +23,8 @@ length_of_longest_word = 0 for word in new_words: if len(word) > length_of_longest_word: - length_of_longest_word = len(word) - longest_so_far = [word] + length_of_longest_word = len(word) + longest_so_far = [word] elif len(word) == length_of_longest_word: longest_so_far.append(word)