title: Returning multiple dictionaries from python function based on calling argument
body: <p>I want my function to return multiple dictionaries based on calling arguments. e.g. if i call the function with no argument, it should return all the dictionaries else if i call it with a list of arguments, it should return the corresponding dictionaries from the function. Apparently if i call with no args or one arg, it works fine but i am having problem with using it with multiple values. Following example shows this problem.</p>
  
  <pre><code>def mydef(arg1=None):
      a = {'a1':1, 'a2':2}
      b = {'b1':1, 'b2':2}
      c = {'c1':1, 'c2':2}
      d = {'d1':1, 'd2':2}
      if arg1 is None:
          return a,b,c,d
      else:
          for x in arg1:
              if x == 'a':
                  return a
              elif x == 'b':
                  return b
  
   w,x,y,z = mydef()
   print type(w)
   print w
  
   s,t = mydef(['a', 'b'])
   print type(s)
   print s
   print type(t)
   print t
  </code></pre>
  
  <p>Doubt: Lists are returned instead of dicts:</p>
  
  <pre><code>def mydef(args=None):
       dicts = { 'a' :{'a1' : 1, 'a2' :2}, 'b' : {'b1' : 1, 'b2' :2}}
       if args is None:
           args = ['a', 'b']
       return [dicts[d] for d in args]
  
  
  x,y = mydef()
  type(x)
  &gt;&gt; type 'dict'
  
  type(y)
  &gt;&gt; type 'dict'
  
  x = mydef(['a'])
  type(x)
  &gt;&gt; type 'list'
  </code></pre>