for i in range(10.0): print(i)
mylist = [1,4,6,2,5,3,7,9] for i in mylist: print(i)
for [blank] in [blank]:
mylist = [1,4,6,2,5,3,7,9] for k in mylist: if k > 3: print(k)
mylist = [1,4,6,2,5,3,7,9] for k in mylist: if k > 3 and k % 3 != 0: print(k)
mylist = [1,4,6,2,5,3,7,9] def is_odd(number): if number % 2 == 0: return True else: return False for k in mylist: print(is_odd(k))
def function_name(param): some operation return statement
function_name(variable) --- class: middle ### Putting Things Together #### Believe or not, you now have the basic building blocks of Python. Almost everything I've covered can get more complicated, but you can do a lot with just this basic toolbox. #### You'll use a function to, say, load a text file into Python, and then you'll loop through each word in the file. You might then use a conditional to see if the word starts with a vowel, and then store the matching words for some later use. Or perhaps you are looking for sentiment terms, or common first names. A great deal of text analysis is done just like this. --- class: middle ### Another Example #### Let's try another example script. It's a dictionary-based approach to solving the New York Times "Spelling Bee" puzzle. #### Before we get into the code, let's take a look at an example of the "Spelling Bee." --- class: middle #### Here's the "Spelling Bee" from two weekends ago. Take 5-7 minutes and see how many words yoiu can come up with. Remember, words have to be five or more letters long, they have to use the center letter, and they can repeat letters as often as you like --- class: middle ### Fork the Repository #### Go to https://github.com/dh-fall-2018/spelling-bee and click the "Fork" button in the upper right-hand corner. A window will pop up asking "Where should we fork this repository?" Choose your account. #### REMINDER: Forking a repo copies it to your Github account, which will give you permission to edit your version of that repo. --- class: middle ### Clone the repo #### Once the repo is forked to your account, you have download a copy to your computer. To do this, open Github Desktop, click "clone a repository", and find the repiository called /spelling-bee in the list of repos you can clone. Click the "clone" button, and the program will copy the repo to a folder located at Documents/GitHub/spelling-bee. --- class: middle ### Run the Jupyter Notebook from the Repo Folder and Look at the Output - #### What is the result? - #### How does the script work?