So, basically I'm trying to convert an ImmutableMultiDict object to a list of lists or dictionary, but I'm having a hard time trying to figure out how. The thing is I have two values for the same key, so when I try the conversion, I can only get 1 value:
ImmutableMultiDict([('name', 'boom'), ('extension', 'pdf'), ('extension', 'doc')])
When I try dict(object)
{'name': 'boom', 'extension': 'pdf'}
Any suggestion?
The ImmutableMultiDict object has a lists method. You can use that to convert it to a dictionary with unified keys that have lists for the values.
from werkzeug import ImmutableMultiDict
d = ImmutableMultiDict([('name', 'boom'), ('extension', 'pdf'), ('extension', 'doc')])
dict(d.lists())
# returns:
{'name': ['boom'], 'extension': ['pdf', 'doc']}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With