Python Data Structure and Containers

Python has several in built data containers to facilitate efficient data storage and retrieval. Some key ones are-

  • List
  • Tuple
  • Dictionary

Let’s look at the above types one by one

List- Lists are mutable (can be edited) and iterable data containers with homogeneous or heterogeneous data. This is one of the most commonly used data structure in Python. A list is denoted by square brackets – “ [ ]

Let’s look at some examples of lists operations-

list3

list4.png

list5

list6

Next, let’s do slicing and dicing of the list. This follows the same zero based indexing as strings

list7

list8.png

list9.png

Tuple- Tuples operations are significantly faster than list, however tuples are immutable. Tuples are best suited for write once and read many times jobs such as big data operations. Similar to list, a tuple can store heterogeneous data.

They are defined by ” ( ) “.  Let’s look at some examples of tuples operations-

tuples

Dictionary- Similar to tuples operations, dictionary operations are significantly faster than that of lists. A dictionary is made of “Key-Value” combinations. Values are generally retrieved by providing the keys.

Dictionaries are defined by ” { } “.  Let’s look at some examples of dictionary operations-

dictionary1.png

dictionary2

You can find much more information on the above objects in Python Official Documentation.

Cheers!

One thought on “Python Data Structure and Containers

  1. Pingback: Learn Python Step by Step | RP's Blog on data science

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s