List and dictionary data structures keep track some of our common information that we need in the following way.
Step-by-step explanation:
Every programming language has provision for data structures. In the Python programming language, there are a total of 4 inbuilt data structures. These are namely list, tuple, dictionary, and set. Each of them is unique in its own right.
List
- A data structure that stores an ordered collection of items in Python is called a list. In other words, a list holds a sequence of items. You need to put all the items, separated by commas, in square brackets to let Python know that a list has been specified. The general syntax of a list is:
- some_list = [item 1, item 2, item 3,….., item n]
- After creating a list in Python, it is possible to search, add, and remove items from the list.
Dictionary
- It stores data in the form of key-value pairs. The keys defined for a dictionary need to be unique. Though values in a dictionary can be mutable or immutable objects, only immutable objects are allowed for keys.
- A dictionary in Python is defined using key-value pairs, separated by commas, enclosed within curly braces. The key and value are separated using a colon.
- The general syntax of a dictionary is: some_dictionary ={key 1 : value 1, key 2 : value 2, key 3 : value 3,…., key n : value n}