Last active
May 7, 2018 11:24
-
-
Save suryasr007/8e8633831729a3ec765dafa399a48d7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Defining a dictionary | |
| >>> tel = {'jack': 4098, 'sape': 4139} | |
| # If dict keys are only string, we can define as below | |
| >>> dict(sape=4139, guido=4127, jack=4098) | |
| {'sape': 4139, 'jack': 4098, 'guido': 4127} | |
| # Appending a new key value pair to the `tel` dict | |
| >>> tel['guido'] = 4127 | |
| # Display items in dictionary | |
| >>> tel | |
| {'sape': 4139, 'guido': 4127, 'jack': 4098} | |
| # Delete a item from `tel` dict | |
| >>> del tel['sape'] | |
| # Represent all the keys of the `tel` in a list | |
| >>> list(tel.keys()) | |
| ['irv', 'guido', 'jack'] | |
| # sort the keys | |
| >>> sorted(tel.keys()) | |
| ['guido', 'irv', 'jack'] | |
| # Check whether a key exists in the `tel` dict | |
| >>> 'guido' in tel | |
| True | |
| >>> 'jack' not in tel | |
| False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment