Saturday, September 6, 2025
HomeLanguagesHow to extract the data from an ImmutableMultiDict

How to extract the data from an ImmutableMultiDict

Perquisites : ImmutableMultiDict

In this article, we are going to use ImmutableMultiDict to extract the data using Python, which is a type of Dictionary in which a single key can have different values. It is used because some form elements have multiple values for the same key and it saves the multiple values of a key in form of a list.

Examples 1:

In this example .get() function is used to get the value from the corresponding key.

Python3




from werkzeug.datastructures import ImmutableMultiDict
  
data = ImmutableMultiDict([('username', 'Ryan'), 
                           ('password', 'QWERTY')])
print(data.get('username'))


Output:

Ryan

Examples 2:

The same thing can be achieved even if there are many values to the same key.

Python3




from werkzeug.datastructures import ImmutableMultiDict
  
data = ImmutableMultiDict([('username', 'Ryan'),
                           ('password', 'QWERTY'),
                           ('password',123456)])
print(data.getlist('password'))


Output:

['QWERTY', 123456]

Examples 3:

Moreover, we can also change the output result into a Dictionary type.

Python3




from werkzeug.datastructures import ImmutableMultiDict
  
data = ImmutableMultiDict([('username', 'Ryan'), 
                           ('password', 'QWERTY'), 
                           ('password',123456)])
print(data.to_dict(flat=False))


Output:

{'username': ['Ryan'], 'password': ['QWERTY', 123456]}

So, this is how you extract data from an ImmutableMultiDict

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS