Wrap Your Code Into a Function
I’m going here to indent all of the code that I wrote so far, which is creating this empty
nouns list, and then iterating over the initial
nouns list that actually contains the nouns that I’m going to access through the variable that I’m passing as an argument to the
It’s going to create a new variable called
nouns that points to an empty list. Then it’ll do a loop three times where it picks out a random word from the
nouns list that’s nested inside of the
words tuple, and then remove that word from the
nouns list in the
words tuple, and then append it to the
nouns list in the local scope of my
All right. It’s mind-bending to explain it, but I hope you’re following along and that this makes sense. Let’s try it out. I’m printing out the
nouns, and so I should be getting the same result that I did earlier, now that I’m calling the function.
Become a Member to join the conversation.