Day-11 || Data-Collection Dictionary ||

Python

Day-11 || Data-Collection Dictionary ||

Hello Wizards, Firstly I wanna thank you for encouraging me on doing this stuff, and I wanna congratulate you too, cause you reached to the last topic of core python of our curriculum.And today’s topic is a dictionary.

It is similar to the dictionary we use in our daily life, let me explain in detail how to do search the words in the dictionary??

Anybody answer this, simply by using the key values[means a particular letter]. Here also every dictionary consists of the key and value.

congrates

Let’s start with a definition.

Definition:

Dictionary is the sequence of items, each item is the pair made of a key & value. Dictionaries are not sorted so you can access them through the keys (or) values independently.

Creation of Dictionary:

Creating a dictionary is a simple as placing the items inside the curly braces {} separated by the comma [,] indicated as Key: Value.

dict examples

dict examples

dict examples

fromkeys() method:

It creates a new dictionary from the given sequence of elements by the given user.

SYNTAX: dict.fromkeys(sequence,[,value])

The sequence of the elements which is used as keys for the new dictionary, and value which is set for each element of the dictionary. It is optional.

get() method:

It returns the specified value if the key is in the dictionary.

SYNTAX: dict.get(key,[,value]

The default value is none. Key is to be searched in the dictionary.

items() method:

It returns a view object that displays a list of dictionary(key,value) tuple pairs.

SYNTAX: dict.items()

update() method:

It updates the dictionary from the other dictionary.

SYNTAX: dict.update(dict1)

pop() method:

It removes & returns an element from a dictionary having the given key.

SYNTAX:  dict.pop(key)

popitem():

It returns and removes an arbitrary element pair from the dictionary.

SYNTAX: dict.popitem()

membership [dictionary operation]:

It checks whether the key is present in the dictionary (or) Not. It works only for the keys not for the values.

dict methods

dict methods

dict methods

Wizards, this is the last topic in the Core Python, and i will soon start my Advance Python. Thank you for encouraging me these days and if your stuck some where comment below I am for your support, and I wanna go for Bed….. BYE:)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.