title: Generating gray codes.
body: <p>I tried generating gray codes in <em>Python</em>. This code works correctly. The issue is that I am initialising the base case (<code>n=1,[0,1]</code>) in the <code>main</code> function and passing it to <code>gray_code</code> function to compute the rest. I want to generate all the gray codes inside the function itself including the base case. How do I do that?</p>
  
  <pre><code>def gray_code(g,n):
      k=len(g)
      if n&lt;=0:
          return
  
      else:
          for i in range (k-1,-1,-1):
              char='1'+g[i]
              g.append(char)
          for i in range (k-1,-1,-1):
              g[i]='0'+g[i]
  
          gray_code(g,n-1)
  
  def main():
      n=int(raw_input())
      g=['0','1']
      gray_code(g,n-1)
      if n&gt;=1:
          for i in range (len(g)):
              print g[i],
  
  main()
  </code></pre>
  
  <p>Is the recurrence relation of this algorithm <code>T(n)=T(n-1)+n</code> ?</p>