What is a dictionary and what is it’s use in python programming, python dictionary is a another data type where we store data in terms of key value pair.
You might have heard this dictionary in iOS swift programming language and also similar way of storing data in key value pairs in android too called as Map in android.
In our previous tutorial on python set we have seen that set is denoted by { } and elements in between and set avoids repeated elements the same scenario for dictionary.
A dictionary is a built-in data structure in Python that stores a collection of key-value pairs. Each key-value pair is known as an item, and the keys in a dictionary must be unique and immutable. The values can be of any data type, including lists, tuples, and even other dictionaries.
Dictionary is also represented by { } with key – value pair avoiding duplicate elements.You can create a dictionary in Python using curly braces {}
or by calling the dict()
constructor.
For detailed video tutorial may visit below
user = { 'name' : 'abhi', 'age' : 25 }
user ( try to print user )
{ 'name' : 'abhi', 'age' : 25 }
You can specify the key and fetch value
user[ 'name' ]
abhi
user [ 'age' ]
25
we can also make use of get() to fetch the value as
user.get( 'name' )
abhi
user [ 'email' ] = "abc@mail.com"
now print user
{ ‘name’ : ‘abhi’, ‘age’ : 25, ’email’ : ‘abc@mail.com’ }
Deleting data from dictionary :
del user [ 'age' ]
{ ‘name’ : ‘abhi’, ’email’:’abc@mail.com’ }
Using dictionary we can fetch the data much faster and easier also we can avoid duplicate values in this way so mostly we use dictionary for fetching api data.
Python dictionaries are widely used in many applications, including web development, data science, machine learning, and more. Here are some common use cases for Python dictionaries:
Dictionaries are often used to store and retrieve data in a key-value format. For example, a web application might use a dictionary to store user information, with the user’s email address as the key and a dictionary of user data as the value.
Dictionaries can be used to count the occurrences of elements in a list or string. For example, you could use a dictionary to count the number of times each word appears in a text document.
Dictionaries can be used to store configuration settings for an application. For example, a web application might use a dictionary to store the database credentials or other settings.
Dictionaries can be used to group data by a certain attribute. For example, you could use a dictionary to group a list of students by their grade level.
Dictionaries can be used to cache data that is expensive to compute. For example, a web application might use a dictionary to cache the results of a database query so that subsequent requests can be served more quickly.
Dictionaries can be used to implement graphs in Python. Each node in the graph can be a key in the dictionary, and the value can be a list of adjacent nodes.
JSON (JavaScript Object Notation) is a popular format for exchanging data between web services. Dictionaries can be used to parse and manipulate JSON data in Python.
Overall, Python dictionaries are a versatile and powerful tool that can be used in a wide variety of applications.
If you have any query’s in this tutorial on python dictionary do let us know in the comment section below.If you like this tutorial do like and share us for more interesting updates.
5G and 6G Technology AdvancementsWhat is 5G, and How Has It Transformed Connectivity?1. Understanding 5G…
IntroductionInitial StagesEvolutionChallenging Other LanguagesCurrent TrendsAI and HTMLConclusion Introduction HTML, or HyperText Markup Language, is the…
Increase in 80CDemands and Discussions: Increase in 80C Section 80C of the Income Tax Act…
IntroductionWhat is ChatGPT-4?Key Features of ChatGPT-4Enhanced Natural Language UnderstandingImproved Response GenerationVersatilityApplications of ChatGPT-4Customer SupportContent CreationEducational…
APJ Abdul Kalam Biography :Childhood :Academics :Professional Career :Achievements : APJ Abdul Kalam Biography :…
We value your feedback! Please share your thoughts on this blog on Srinivasa Ramanujan Biography…
This website uses cookies.