title: ATBSWP Chapter 4 practice project: Comma Code
body: <p>So the practice project is as follows:</p>
  
  <p>Say you have a list value like this: <code>spam = ['apples', 'bananas', 'tofu', 'cats']</code>
  Write a function that 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 previous <code>spam</code> list to the function would return <code>'apples, bananas, tofu, and cats'</code>. But your function should be able to work with any list value passed to it.</p>
  
  <p>So far I've come up with this:</p>
  
  <pre><code>spam = ['apples', 'bananas', 'tofu', 'cats']
  
  def commacode(a_list):
      a_list.insert(-1, 'and')
      print(a_list)
  
  commacode(spam)
  </code></pre>
  
  <p>And of course the output is just the list values.  I've tried to make line 5 as <code>print(str(a_list))</code>, but that gives a syntax error. My line of thinking is that I have to change it to a string, but I'm lost. Am I missing something in the chapter? I've felt like I've gone over it several times. I feel like <code>len(a_list)</code> should be somewhere in there but that would just give me a value of <code>5</code>.  Any thoughts, or how I should go about thinking about this would be great help. I always feel like I'm really understanding this stuff and then I get to these practice projects and am ALWAYS confused on what to do.  I know the practice projects are going to use some information we've learned in previous chapters and then focus mainly on the chapter we are on. Chapter 4 covers lists, list values, string values, tuples, <code>copy.copy()</code>, and <code>copy.deepcopy()</code> just to name a few.</p>
  
  <p>Link - <a href="https://automatetheboringstuff.com/chapter4/" rel="nofollow noreferrer">Chapter4</a></p>