title: Iterating over list or single element in python
body: <p>I would like to iterate over the outputs of an unknown function. Unfortunately I do not know whether the function returns a single item or a tuple. This must be a standard problem and there must be a standard way of dealing with this -- what I have now is quite ugly. </p>
  
  <pre><code>x = UnknownFunction()
  if islist(x):
      iterator = x
  else:
      iterator = [x]
  
  def islist(s):
      try:
          len(s)
          return True
      except TypeError:
          return False
  
  for ii in iterator:
      #do stuff
  </code></pre>