What is the difference between List and Dictionary data types in Python?

Main differences between List and Dictionary data types in Python are as follows:

  • Syntax: In a List we store objects in a sequence. In a Dictionary we store objects in key-value pairs.
  • Reference: In List we access objects by index number. It starts from 0 index. In a Dictionary we access objects by key specified at the time of Dictionary creation.
  • Ordering: In a List objects are stored in an ordered sequence. In a Dictionary objects are not stored in an ordered sequence.
  • Hashing: In a Dictionary, keys have to be hashable. In a List there is no need for hashing.
Read the full book at www.amazon.com
Posted in Python, Python Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*