top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python Dictionaries Overview

Writer's picture: bismark boatengbismark boateng

Python dictionaries is one of the data types in python a developer

or a data scientist can work with.

It's a special kind of data type that accepts and store two entities,

one being a key, and the other being a value.


A key correspond to a value.

key's can be an integer or a string etc.


Creating a dictionary

dict_1 = {} 

When a dictionary is created using the above code, one can opt to either

hardcode the key and value pairs into the dictionary or can loop through

a dataset and update those values into the dictionary created.


An example of a dictionary:


#dictionary 
dict_1 = { 
      "name" : "jack", 
      "age" : 12, 
      "height" : 2.3
      } 
print(dict_1["name"]) 

In the above code, a dictionary called dict_1 is created and the details of a person is added into it.

The details contain the person's name, age and height .

unlike lists, dictionaries can be called by it's key. thus, to get the value of jack, the snippet of code wrapped in the print() function above does that.



likewise, to get the height of jack:


print(dict_1["height"]) 

the code above print statement above outputs the height of jack from

the dictionary data type .


Adding key value pairs into a dictionary

Since a dictionary accepts a key, value pair, to add a data into the

dictionary, one has to specify the key that corresponds to the value he or she wants to assign it to


dict_2 = {"sex": "Male"} 
dict_1.update(dict_2) 

In the above code, the sex of jack is specified as Male and it's being updated into the main dictionary dict_1.

take note; the update() method is used here, the update method accepts two values, meanwhile, since we passed in a dictionary, python will throw us an error



 
 

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page