title: Creating a function that takes a list or integer as argument (Python)
body: <p>I'm trying to create a function that gives the average of either a list of numbers or just integers as variables. So far I have:</p>
  
  <pre><code>def average(*args):
      if type(args) is list:
          for x in args:
              print sum(x) / float(len(x))
      else:
          for x in args:
              args = list(args)
              print sum(x) / float(len(x))
  </code></pre>
  
  <p>When I input a list, like </p>
  
  <pre><code>average([1, 3, 5, 2])
  </code></pre>
  
  <p>it works great. But when I enter in</p>
  
  <pre><code>average(1, 3, 5, 2)
  </code></pre>
  
  <p>it gives "TypeError: 'int' object is not iterable".
  I've checked other questions but none of the solutions seem to work. I've tried to check if it's a list with type() and isinstance() but whenever I get one of them to work, the other throws out an error.</p>