# Declaring a dictionary dictionary = {} dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23} print(dictionary) print(type(dictionary)) # Accessing the elements in a dictionary dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23} print(dictionary) print(dictionary['Name']) print(dictionary['Sex']) dictionary['Height'] print(dictionary.get('Age')) # Removing the elements from a dictionary dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) # Deleting an element del dictionary['Name'] print(dictionary) # Popping an item print(dictionary.popitem()) # Popping the value print(dictionary.pop('Sex')) print(dictionary) # Clearing the entire dictionary dictionary.clear() print(dictionary) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) # Iterating through the values for i in dictionary: print(dictionary[i]) # Iterating through the keys for i in dictionary: print(i) dictionary = {0: "Tanu", 1: "Prabhu"} print(dictionary) print(all(dictionary)) dictionary = {1: "Tanu", 1: "Prabhu"} print(all(dictionary)) dictionary = {} print(all(dictionary)) dictionary = {0: "Tanu", 1: "Prabhu"} print(dictionary) print(any(dictionary)) dictionary = {0: "Tanu", 0: "Prabhu"} print(any(dictionary)) # 0 is False dictionary = {0: "Tanu"} print(any(dictionary)) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) print(len(dictionary)) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) # Sorting in a ascending order print(sorted(dictionary)) # Sorting in a descending order print(sorted(dictionary, reverse = True)) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) dictionary1 = {} print(dictionary1) dictionary1 = dictionary.copy() print(dictionary1) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) print(dictionary.keys()) dictionary = {'Name': 'Tanu', 'Sex': 'Male', 'Age': 23, 'Height': 5.8, 'Occupation': 'Student'} print(dictionary) print(dictionary.values())