L 27: DICTIONARY IN PYTHON | PYTHON DICTIONARY TUTORIAL | PYTHON COURSE FOR BEGINNERS

Опубликовано: 21 Октябрь 2021
на канале: Parnika Tutorials
470
16

In this video, I have discussed about dictionary in python and its operations like pop, popitem, values, keys, etc,.
Python dictionary is an unordered collection of items. Each item of a dictionary has a key/value pair.
Dictionaries are optimized to retrieve values when the key is known.

Creating Python Dictionary:
Creating a dictionary is as simple as placing items inside curly braces {} separated by commas.
An item has a key and a corresponding value that is expressed as a pair (key: value).
While the values can be of any data type and can repeat, keys must be of immutable type (string, number or tuple with immutable elements) and must be unique.

Accessing Elements from Dictionary:
While indexing is used with other data types to access values, a dictionary uses keys. Keys can be used either inside square brackets [] or with the get() method.
If we use the square brackets [], KeyError is raised in case a key is not found in the dictionary. On the other hand, the get() method returns None if the key is not found.

Changing and Adding Dictionary elements:
Dictionaries are mutable. We can add new items or change the value of existing items using an assignment operator. If the key is already present, then the existing value gets updated. In case the key is not present, a new (key: value) pair is added to the dictionary.

Removing elements from Dictionary
We can remove a particular item in a dictionary by using the pop() method. This method removes an item with the provided key and returns the value.
The popitem() method can be used to remove and return an arbitrary (key, value) item pair from the dictionary. All the items can be removed at once, using the clear() method.
We can also use the del keyword to remove individual items or the entire dictionary itself.

Python Dictionary Methods
Methods that are available with a dictionary are listed below

Clear(): Removes all items from the dictionary.

copy(): Returns a shallow copy of the dictionary.

fromkeys(seq[, v]) : Returns a new dictionary with keys from seq and value equal to v (defaults to None).

get(key[,d]): Returns the value of the key. If the key does not exist, returns d (defaults to None).

items(): Return a new object of the dictionary's items in (key, value) format.

keys(): Returns a new object of the dictionary's keys.

pop(key[,d]): Removes the item with the key and returns its value or d if key is not found. If d is not provided and the key is not found, it raises KeyError.

popitem(): Removes and returns an arbitrary item (key, value). Raises KeyError if the dictionary is empty.

setdefault(key[,d]): Returns the corresponding value if the key is in the dictionary. If not, inserts the key with a value of d and returns d (defaults to None).

update([other]): Updates the dictionary with the key/value pairs from other, overwriting existing keys.
values(): Returns a new object of the dictionary's values
#dictionary #python #parnikatutorials
00:00 Introduction
00:28 What is a dictionary
01:12 How to create a Dictionary
04:09 How to access a value from the dictionary
09:06 Clear method
09:40 Copy method
10:59 Pop & popitem methods
12:37 Implementation in jupyter notebook
Website: www.parnikatutorials.in
Email id: parnikatutorials@gmail.com
To get the regular updates:
Telegram link: https://t.me/Parnikatutorials
Facebook: https://m.facebook.com/profile.php?id...
Linkedin:   / parnika-tutorials-a8a9831b2  
Pinterest:   / parnikatutorials0892  
Instagram:   / parnikatutorials  
Playlists:
Virtual Coffee with Jagadeesh:    • VIRTUAL COFFEE WITH JAGADEESH  
Digital Logic:    • ABOUT PARNIKA TUTORIALS  
Computer Organization and Architecture:    • ABOUT PARNIKA TUTORIALS  
C Programming:    • L 1: WHAT IS AN ALGORITHM AND CHARACTERIST...  
Data Structures:    • L 1: Uncover the Benefits of Linked List: ...  
Theory of Computation:    • ABOUT PARNIKA TUTORIALS  
Compiler Design:    • ABOUT PARNIKA TUTORIALS  
Operating Systems:    • PROCESS STATE DIAGRAM | LONG TERM, SHORT T...  
Databases:    • ABOUT PARNIKA TUTORIALS  
Computer Networks:    • ABOUT PARNIKA TUTORIALS  
For GATE PYQs and much more explore:    / parnikatutorials  


На этой странице сайта вы можете посмотреть видео онлайн L 27: DICTIONARY IN PYTHON | PYTHON DICTIONARY TUTORIAL | PYTHON COURSE FOR BEGINNERS длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Parnika Tutorials 21 Октябрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 470 раз и оно понравилось 16 зрителям. Приятного просмотра!