Let’s look at some crucial features that are very useful when experimenting with dictionaries in Python.
Functions | Description |
---|---|
clear() | Eliminates everything from the dictionary |
copy() | Returns a shallow copy of the dictionary |
fromkeys() | A dictionary is formed using the provided sequence. |
get() | Returns the value for the given key |
items() | Return the list with all dictionary keys with values |
keys() | Returns a view object that shows a list of all the dictionary’s keys in the order they were added. |
pop() | Returns the element with the specified key and removes it. |
popitem() | Returns and removes the key-value pair from the dictionary |
setdefault() | Returns the value of a key if the key is in the dictionary else inserts the key with a value to the dictionary |
update() | Updates the dictionary with the elements from another dictionary |
values() | Returns a list of all the values available in a given dictionary |
Dict={"name": "Coderzpy",
"type": "Educational",
"price": "free",
"work-style": "remote"}
print(len(Dict))
print(Dict.values())
print(Dict.items())
print(Dict.keys())
print(Dict.__contains__('name'))
Dict.clear()
print(Dict)
4
dict_values(['Coderzpy', 'Educational', 'free', 'remote'])
dict_items([('name', 'Coderzpy'), ('type', 'Educational'), ('price', 'free'), ('work-style', 'remote')])
dict_keys(['name', 'type', 'price', 'work-style'])
True
{}
Note: also read about Python Dictionary
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…