title: Confused about a function in Learn Python the Hard Way ex41?
body: <p>I got stuck on another part of this exercise. The program that is being coded allows you to drill phrases (It gives you a piece of code, you write out the English translation) and I'm confused on how the "convert" function works. Full code: <a href="http://learnpythonthehardway.org/book/ex41.html" rel="nofollow">http://learnpythonthehardway.org/book/ex41.html</a></p>
  
  <pre><code>def convert(snippet, phrase):
      class_names = [w.capitalize() for w in
                     random.sample(WORDS, snippet.count("%%%"))]
      other_names = random.sample(WORDS, snippet.count("***"))
      results = []
      param_names = []
  
      for i in range(0, snippet.count("@@@")):
          param_count = random.randint(1,3)
          param_names.append(', '.join(random.sample(WORDS, param_count)))
  
      for sentence in snippet, phrase:
          result = sentence[:]
  
          # fake class names
          for word in class_names:
              result = result.replace("%%%", word, 1)
  
          # fake other names
          for word in other_names:
              result = result.replace("***", word, 1)
  
          # fake parameter lists
          for word in param_names:
              result = result.replace("@@@", word, 1)
  
          results.append(result)
  
      return results
  </code></pre>
  
  <p>I'm pretty lost. Is "w" from <code>w.capitalize()</code> a file itself, or is it just referring to the objects in the list? I'm also not sure why the <code>.count()</code> function is in the argument for <code>.sample()</code> (or what <code>.sample()</code> really does). What is the purpose of the first for_loop?</p>
  
  <p>Thank you for any and all help - I'm sorry for the barrage of questions.</p>