Difference Between List and Dictionary in Python

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

What is List in Python?

In Python, a list is an ordered, mutable collection of elements, enclosed in square brackets [], allowing duplicates and supporting various operations like appending, removing, and slicing.

Let’s take two simple examples to understand operations on Lists in Python.

  • Creation and Basic Operations:
  • Slicing and Indexing:

To learn more, you can visit: List in Python.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

What is Dictionary in Python?

A Python dictionary is an unordered collection that stores data as key pairs, differing from other data types that store single values. In a dictionary, each key pair is delimited by a colon (:), and individual keys are distinguished by commas. This structure offers enhanced optimization.

Example:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Key Difference Between List and Dictionary in Python

The difference between list and dictionary in Python lies in their structure; while a list is an ordered collection indexed by position and allowing duplicates, a dictionary is an unordered collection of unique key pairs.

Lists are best for sequential data, while dictionaries are tailored for data retrieval by specific identifiers.

Dictionaries vs Lists in Python

Difference Between List and Dictionary in Python

PointsListDictionary
BasicsList refers to the collection of index value pair-like arrays in C/C++/Java.Dictionary refers to the hashed structure of various pairs like key-value pairs.
CreationList is initialized with [], and elements are separated by ','.Dictionary is created by placing elements in {}, data is added as key-value pair, and each pair is separated by ','.
AccessingList values can be accessed by numeric indexes.Dictionary items can be accessed by using key values. Key values can be of any data type.
Ordering of ElementsThe order of elements in the list is always maintained.We don’t have any guarantee of maintaining the order of the available elements.
PropertiesList is ordered, mutable, and allows duplicate values.In a dictionary, the dictionary is unordered and mutable, but the dictionary doesn't allow duplicate values with the same key in it.
Store the dataLists are used to store the data, which should be ordered and sequential.It stores large amounts of data for easy and quick access.
IndexingThe indices of lists in python start from zero and are of integer type.The keys in dictionaries are used to access key-value pairs and they can be of any type.
Sortingsort() method sorts the elements of the list.sort() method sort the dictionary elements on the basis of their keys.
ReversalThe reverse() method reverses the list elements.Since dictionary elements are unordered, reversing the elements does not make any sense.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Examples of lists and dictionaries in Python

Example 1: Creating and Accessing values of list and dictionaries in Python

Code:

Output:

Explanation:

The following python code shows us how a list is implemented, how to access the list items with numeric indexing, and the multiple dimension of the list.

Input:

Output:

Explanation: In the following python code, we have declared two dictionaries. In dict, d1 takes numeric values as its keys, i.e., {1,2,3}, whereas in dict d2, it takes string values as its keys. Dictionary d1 can be considered like a list, but the fact is it is dict.

The above example shows the difference between a list and a dictionary.

Example 2: space-time trade-off difference between a list and a dictionary in python

Code:

Output:

Explanation:

In the following python code, we have seen that the dictionary took less time than a list. The list took more time to fetch a single element from the list than that of the dictionary because the dictionary uses a hashtable for implementing the arrangement.

Conclusion

  • In this article, we have seen the difference between a list and a dictionary in python.
  • Later, we have given some examples that will show the differences between both data structures, i.e., list and dictionary.
  • List is a data structure in python that refers to the collection of index value pair-like arrays in C/C++/Java, whereas dictionaries are the data structures that refer to the hashed structure of various pairs like key-value pairs.
  • Lists are used to store the data, which should be ordered and sequential. On the other hand, dictionary is used to store large amounts of data for easy and quick access.
  • List is ordered and mutable, whereas dictionaries are unordered and mutable.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more