1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Python & Machine Learning (with Analytics Vidhya Hackathons)

Exercise

Create a Dictionary

A Dictionary is an unordered set of key:value pairs, with the requirement that the keys are unique (within a Dictionary). A few pointers about dictionary:

  • An empty dictionary can be created by a pair of braces: {}.
  • Dictionary elements can be accessed by dictionary keys
  • DICT.keys() will return all the keys of given dictionary "DICT"
DICT = {
  'Name':'Kunal',
  'Company':'Analytics Vidhya'
  }

#Dictionary elements can be accessed by keys

print (DICT['Name'])

#The above print statement will print Kunal

In dictionary "DICT", Name and Company are dictionary keys whereas "Kunal" and "Analytics Vidhya" are their respective values.

Instructions

100 XP
  • Print the value associated with key 'Age' in dictionary dict1
  • Store all the keys of dictionary dict1 in variable 'dict_keys'