title: Automate the boring stuff with Python: Comma Code
body: <p>Currently working my way through this beginners book and have completed one of the practice projects 'Comma Code' which asks the user to construct a program which:</p>
  
  <blockquote>
    <p>takes a list value as an argument and returns
    a string with all the items separated by a comma and a space, with and
    inserted before the last item. For example, passing the <strong>below</strong> spam list to
    the function would return 'apples, bananas, tofu, and cats'. But your function
    should be able to work with any list value passed to it.</p>
  </blockquote>
  
  <pre><code>spam = ['apples', 'bananas', 'tofu', 'cats']
  </code></pre>
  
  <p>My solution to the problem (Which works perfectly fine):</p>
  
  <pre><code>spam= ['apples', 'bananas', 'tofu', 'cats']
  def list_thing(list):
      new_string = ''
      for i in list:
          new_string = new_string + str(i)
          if list.index(i) == (len(list)-2):
              new_string = new_string + ', and '
          elif list.index(i) == (len(list)-1):
              new_string = new_string
          else:
              new_string = new_string + ', '
      return new_string
  
  print (list_thing(spam))
  </code></pre>
  
  <p>My only question, is there any way I can shorten my code? or make it more 'pythonic'?  </p>
  
  <p>Here is my code.</p>
  
  <pre><code>def listTostring(someList):
      a = ''
      for i in range(len(someList)-1):
          a += str(someList[i])
      a += str('and ' + someList[len(someList)-1])
      print (a)
  
  spam = ['apples', 'bananas', 'tofu', 'cats']
  listTostring(spam)
  </code></pre>
  
  <p>output: apples, bananas, tofu, and cats </p>