Skillshare intro to Python/Unit 5: Difference between revisions

no edit summary
imported>Jesstess
(Created page with "right|300px == Project == It is time for our pièce de résistance! We are going to write a Scrabble cheater from scratch in Python. == Goals for this...")
 
imported>Jesstess
No edit summary
Line 12:
* practice working with dictionaries and for loops
 
=== Problem statement ===
 
Write a Python script that takes a Scrabble rack (the Scrabble letters you have to play) as a command-line argument and prints all valid Scrabble words that can be constructed from that rack, along with their Scrabble scores, sorted by score.
Line 41:
</pre>
 
===Resources===
 
* http://courses.cms.caltech.edu/cs11/material/advjava/lab1/sowpods.zip contains all words in the official [http://en.wikipedia.org/wiki/SOWPODS SOWPODS] word list, one word per line.
Line 54:
</pre>
 
===Breaking down the problem===
 
====Step 1: construct a word list====
 
Write the code to open and read the sowpods word file. Create a list, where each element is a word in the sowpods word file. Note that each line in the file ends in a newline, which you'll need to remove from the word.
Line 71:
 
 
====Step 2: get the rack====
 
Write the code to get the Scrabble rack (the letters available to make words) from the command line argument passed to your script. For example if your script were called `scrabble_cheater.py`, if you ran <tt>python scrabble_cheater.py RSTLNEI</tt>, <tt>RSTLNEI</tt> would be the rack.
Line 89:
 
 
====Step 3: find valid words====
 
Write the code to find all words from the word list that are made of letters that are a subset of the rack letters. There are many ways to do this, but here's one way that is easy to reason about and is fast enough for our purposes: go through every word in the word list, and for every letter in that word, see if that letter is contained in the rack. If it is, save the word in a <tt>valid_words</tt> list. Make sure you handle repeat letters: once a letter from the rack has been used, it can't be used again.
Line 116:
 
 
===Checking your work===
 
What happens when you run your script on the following inputs?
Anonymous user