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
- The list is a mutable data type .
- A list is enclosed within the square brackets [ ].
- It has a proper way of indexing.
- Eg [1,2,3,45,88,0]
DICTIONARY
- Dictionary is a mutable data type, but keys are to be of immutable type and values can be of any type.
- It is enclosed within the curly bracket { }.
- It is a combination of keys and values.
- Here, its keys serve as its index values.
- Eg {1:'a’ ,2:'b’}