title: Type deduction in Python
body: <p>Is there a better way in Python to determine whether a function argument is a single number or a list of numbers.  Currently I'm using the side effect of an exception to channel control flow, but it doesn't seem elegant:</p>
  
  <pre><code>def buildPattern( NumberOrList, Framework ):
      FinalPattern = '--&gt;'
      try:
          ListLen = len(NumberOrList)
          #if this is a list, program flow will reach this point
          I = 0
          for Char in Framework:
              if Char == 'x':
                  FinalPattern = FinalPattern + ' ' + str(NumberOrList[I])
                  I = (I+1) % ListLen
              else:
                  FinalPattern = FinalPattern + '  '
      except:
          #if we reach this point, we don't have a list... (or some other problem)
          for Char in Framework:
              if Char == 'x':
                  FinalPattern = FinalPattern + ' ' + str(NumberOrList)
              else:
                  FinalPattern = FinalPattern + '  '
      return FinalPattern
  
  print buildPattern( 3,'x x x x x x x x ' ) #single number call
  print buildPattern( [1,3,5], 'x x x x x x x x ' ) #list call
  </code></pre>