Monday, October 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
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6780 POSTS0 COMMENTS