PanaceaMUJ / CloneWars22

Contributions to Clone Wars 2022 (October 2022)
GNU Affero General Public License v3.0
2 stars 15 forks source link

Create DICTIONARY_SHUBH_GOEL.py #32

Open vader22a opened 2 years ago

vader22a commented 2 years ago

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. Line no.1

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 [], Key Error 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.Line no. 19

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.Line no. 38

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 pop item() 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.Line no. 55