What are list and dictionary in Python

List and Dictionary in Python

A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
ref: https://www.w3schools.com/python/python_lists.asp
Dictionary: A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.
https://www.w3schools.com/python/python_dictionaries.asp

1 Like

Python list is a collection of pointers to the objects . Though it seems like a normal array , it has many things with in it . On the other hand , dictionaries are a tree like data structure , say Red-black trees etc . It is almost same like a Hash-map in Java .

  • Python list can be accessed using 0 based indexing like normal arrays or using -ve indexing .
  • Python dictionaries has many ways of accessing like dict[keyvalue] or , dict.values etc

LIST

  1. The list is a mutable data type .
  2. A list is enclosed within the square brackets [ ].
  3. It has a proper way of indexing.
  4. Eg [1,2,3,45,88,0]

DICTIONARY

  1. Dictionary is a mutable data type, but keys are to be of immutable type and values can be of any type.
  2. It is enclosed within the curly bracket { }.
  3. It is a combination of keys and values.
  4. Here, its keys serve as its index values.
  5. Eg {1:'a’ ,2:'b’}