blog header

Python List Vs Dictionary in Python

Python List Vs Dictionary in Python

Python List vs Dictionary in Python: Comparison

We all know that python is an easy and efficient programming language unlike other programming languages and this is because Python supports a variety of built-in data structures. These data structures in Python are in sequence form and store data in different formats unlike others. 
And here we discuss those two data structures in Python that are List and Dictionary which are simple but have a powerful effect and have the ability to store a wide range of data. So, let us clearly understand List vs Dictionary in Python with the exact meaning and dive into the depth of the difference between List and Dictionary in Python and learn more about them.


What do you mean by List in Python?

List as a data structure is one of the fundamentals in Python and is a sequential form of objects which is static in nature, i.e. it can be addable, removable and mutable. Each value present inside the list is known as an item. List is used to store a collection of objects in Python and represent values between square brackets [ ] and separate the values with commas.

For example:

my_list = [11, 22, 33, 44] 
print(my_list) 

# Output: [11, 22, 33, 44]


What do you mean by Dictionary in Python?

Dictionary is a default data structure in Python and it stores a collection of data in an unordered manner and it is mutable and indexed. In Python, dictionaries are written inside curly brackets {}, separated by commas and contain keys and values. The key and value of the data are separated by a semicolon (:). The key name of each value is unique and case sensitive and the dictionary can be accessed through the key name.

For example:

my_dict = {
  "name": "Raju",
  "age": 26,
  "country": "India"
}
print(my_dict)

Output:
{'name': 'Raju', 'age': 26, 'country': 'India'}


Difference between List and Dictionary in Python

 

  • Meaning: List is a collection of different objects in an ordered manner similar to an array in C++, but a Dictionary is a collection of data values in the form of key-value pairs as a hashed structure.
  • Arrangement: The arrangement of items in a List is placed inside square brackets [ ], separated by commas (,), whereas in a Dictionary all key-values placed inside curly brackets {} are separated by commas. And each key and value are separated by a semicolon (:).
  • Index Type: Index values in List are integer values starting from 0 but keys in Dictionary are of a given data type.
  • Mode of Access:In List, items are accessed through index values whereas in Dictionary, items are accessed using keys.
  • Order of items: The default order of items in the list is always maintained but there is no guarantee that the order will be maintained in the dictionary.
  • Mutable: Lists are mutable in nature whereas dictionaries are also mutable but do not follow repetition.
  • Formation: List object is created using list() function, but dictionary object is created in dict() function.
  • Sort(): In List, the sort() method sorts the items in ascending or descending order but in the Dictionary, it sorts the keys by default.
  • Count():The count() method returns the number of elements shown in the list, whereas it is not present in the dictionary.
  • Reverse(): In a list, reverse() is reversing the list items, but the items cannot be reversed because they are key-value pairs in the dictionary.


Approach of List

  • List is used to store data, which is in a sorted and ordered manner.
  • List is used in database
  • It is in JSON format
  • Lists are extremely useful for array operations

Approach of Dictionary

  • In Python, a Dictionary is used as a switch statement.
  • It used to store large amount of data for easy and quick access
  • Dictionaries are used to index content.
  • Dictionaries are used when there is a need to create Map objects.
  • It is used to create a data frame with lists
  • Dictionaries are also used in JSON


CONCLUSION:

So in the above talk, we learned about Lists and Dictionaries which are the most basic data structures in Python programming. Both are different from each other and have their own differences in many ways like arrangement, formation, index type, etc. These two are the most important data structures while programming in Python. I hope this blog will be useful to you and do check out other blogs by AP2V to know more about such programming concepts.

Our Related Courses:

NEWSLETTER

Submit to our newsletter to receive exclusive stories delivered to you inbox!

We'll never share your email with anyone else.
course

Related Category Courses

Chat

Sign in to your account

Sign in to your account

Welcome back! Login with your data that you entered during registration.

Don't have an account? Sign up

Forget Password

We will send a password reset link on your email.

Create Account

Create Account

Use your email for registration.

Already on Ap2v.com Sign in