Before going through the actual content i.e. the implementation of a dictionary, it is important to know some basic theories so that we can know what we are going to learn and why we are spending our precious time learning it.
“Python dictionary is an unordered collection of items. Each item of the dictionary has a key and value pair/ key-value pair.”
Every programming language has its own distinct features, commonly known as its key features. With that said, Python’s one out of the box feature is “dictionaries”. Dictionaries may look very similar to a “List”, but dictionaries have some distinct features that do not hold true for other data types like lists, and those features make it (python dictionary) special.
Here are a few important features of a python dictionary:
If we talk a little about how it works, its syntax comprises of key and values separated by colons in curly brackets, where the key is used as a keyword, as we see in real life dictionaries, and the values are like the explanation of the key or what the key holds (the value). And for the successful retrieval of the data, we must know the key, so that we can access its value just like in a regular oxford dictionary where if we don't know the word or its spelling, we cannot obtain its definition. Let's look into the syntax of a Python dictionary
a = {'key', 'value', 'cow':'mooh'}
print(a['cow'])
#will print "mooh" on the screen
With the help of dictionaries, we do not have to do most of our work manually through code like in C or C++. What I mean by this is that Python provides us with a long list of already defined methods for dictionaries that can help us to do our work in a shorter span of time with a very little amount of code. Some of these methods are, clear(), copy(), popitem(), etc. The best part about them is that no extra effort is required to be put in order to learn the functionality as their names explain their functions (in most of the cases), such as clear() will clear all the data from the dictionary, making it empty, copy() will make a copy of the dictionary, etc.
Some distinct features that a dictionary provides are:
This was pretty much about dictionaries in Python. You will get further details along with explanations and implementation in the video tutorial.
I hope you are enjoying it. Do not forget subscribing to CodeWithHarry.
# Dictionary is nothing but key value pairs
d1 = {}
# print(type(d1))
d2 = {"Harry":"Burger",
"Rohan":"Fish",
"SkillF":"Roti",
"Shubham":{"B":"maggie", "L":"roti", "D":"Chicken"}}
# d2["Ankit"] = "Junk Food"
# d2[420] = "Kebabs"
# print(d2)
# del d2[420]
# print(d2["Shubham"])
# d3 = d2.copy()
# del d3["Harry"]
# d2.update({"Leena":"Toffee"})
# print(d2.keys())
# print(d2.items())
print("Select any word to get its meaning\n", "1) Abandoned\n", "2) Plethora\n", "3) Imbibe\n", "4) Inculcate\n") Dic1 = {"Abandoned":{"deserted", "forsaken", "cast aside/off", "jilted", "stranded", "rejected"}, "Plethora":"excess", "abundance", "overabundance", "superfluity", "surfeit", "Imbibe": "drink", "consume", "sup", "sip", "quaff", "swallow", "down", "guzzle", "Inculcate": "instil", "implant", "fix", "ingrain", "infuse", "impress", "imprint"} Print(Dic1) I am unable to run this it's showing error
broo plss watch the python tutorial once again.and try karoo
Print kike ho one side another side print like ho
Pehle line me aap vo dictionary ke andar dictionary leeke he lagta he vo list or tuple hona chahiye qnki dictionary ke andar dictionary ese nahi banate he
print("Select any word to get its meaning\n", "1) Abandoned\n", "2) Plethora\n", "3) Imbibe\n", "4) Inculcate\n") Dic1 = {"Abandoned":{"deserted", "forsaken", "cast aside/off", "jilted", "stranded", "rejected"}, "Plethora":"excess", "abundance": "overabundance", "superfluity": "surfeit", "Imbibe": "drink", "consume": "sup", "sip": "quaff", "swallow": "down", "guzzle": "Inculcate", "instil": "implant", "fix": "ingrain", "infuse": "impress"} print(Dic1)
thank you sir for providing free python courses and materials
Full Notes and Source Code ::::::::::} https://github.com/Optimized-World/Complete-Python-Tutorial-and-Notes |::::::::::::| Thanks, Harry Bhai for Awesome Tutorials
hey . how can i add the key and value inside the dictionary named shubham (in your example ).
thank you sir
d1={"vishnu":"god","house":"home","mom":["mother","maa","mummy"]} print(d1) #take input from user print("input any of three vishnu/house/mon") print(d1[input()])
No downloadable resources for this video. If you think you need anything, please post it in the QnA!
Any Course related announcements will be posted here