title: What is the correct syntax in python for defining functions, declaring variables?
body: <p>Why is this code producing syntax errors? It also is telling me return is outside the function block.  With this code - running Python 2.7.8 with iPython 4.0.0</p>
  
  <pre><code>def get_entropy(source):
      symbol_list = [[],[]]
      entropy = 0.0
  
      #get the Pi's
      for i in source:
          if i in symbol_list[0]:
              symbol_list[0].append(i)
              symbol_list[1].append(source.count(i)/float(source.len())
  
      for i in symbol_list[1]:
          entropy = entropy + entropy * math.log(i, 2)
  
      return entropy 
  </code></pre>
  
  <p>When I run put this into the interpreter it's telling me</p>
  
  <pre><code>  File "&lt;ipython-input-1-765444f039bb&gt;", line 11
      for i in symbol_list[1]:
                             ^
  SyntaxError: invalid syntax
  
  ---------------------------------------------------------------------------
  NameError                                 Traceback (most recent call last)
  &lt;ipython-input-2-fda3e1b00a22&gt; in &lt;module&gt;()
  ----&gt; 1 entropy = entropy + entropy * math.log(i, 2)
  
  NameError: name 'entropy' is not defined
    File "&lt;ipython-input-3-c24513b23f5d&gt;", line 1
      return entropy
  SyntaxError: 'return' outside function
  </code></pre>
  
  <p></p>
  
  <p>When I run try to execute it as a script it tells me there is a syntax error on whatever the next line is following the first "for" block.  What am I missing?</p>