How to get multiple parameters with same name from a URL in Pylons?
Question: So unfortunately I find myself in the situation where I need to modify an
existing Pylons application to handle URLs that provide multiple parameters
with the same name. Something like the following...
domain:port/action?c=1&v=3&c=4

Conventionally the parameters are accessed this way...

    
    
    from pylons import request
    c = request.params.get("c")
    #or
    c = request.params["c"]
    

This will return "4" as the value in either case, because ignoring all but the
last value seems to be the standard behavior in these situations. What I
really need though, is to be able to access both. I tried printing out
request.params and get something like this...

    
    
    NestedMultiDict([(u'c', u'1'),(u'v', u'3'),(u'c', u'4')])
    

I haven't found a way to index into it, or access that first value for c.

I found a [similar question](http://stackoverflow.com/questions/353379/how-to-
get-multiple-parameters-with-same-name-from-a-url-in-php) relating to this
problem, but solved with PHP:

Something along these lines would work well for me, but maybe some Python code
that would fit into Pylons. Has anyone dealt with something like this before?


Answer: From the docs -
<http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/glossary.html#term-
multidict> :

> multidict An ordered dictionary that can have multiple values for each key.
> Adds the methods getall, getone, mixed, add and dict_of_lists to the normal
> dictionary interface. See Multidict and pyramid.interfaces.IMultiDict.

So just call:

    
    
    request.params.getall('c')
    

