Create AI Video
Create AI Video

List and dictionaries in python

mim
2024-10-13 21:28:47
Lists and Dictionaries in Python are inbuilt data structures that are used to store data. Lists are linear in nature whereas dictionaries stored the data in key-value pairs.Lists :Lists are heterogenous and can contain different types of data such as Integers, Strings, Lists, as well as inbuilt or user-defined Objects. Lists are mutable, which means that if we modify the list, then any other variable referencing to this list also gets modified.Dictionaries :Dictionaries used to store values in key-value pairs. They are created by placing elements in { } as key:value, with each pair separated by commas. Unlike lists, dictionaries use keys (which can be of any immutable data type) to access values, rather than integer indices. Dictionaries are mutable and can't contain duplicate keys, but can have duplicate values.Difference between lists and dictionaries:1. The list is a collection of index value pairs like ArrayList in Java and Vectors in C++.The dictionary is a hashed structure of the key and value pairs.2. The list is created by placing elements in [ ] separated by commas “, “The dictionary is created by placing elements in { } as “key”:”value”, each key-value pair is separated by commas “, “3. The indices of the list are integers starting from 0.The keys of the dictionary can be of any immutable data type.4. Lists can duplicate values since each values have unique index. Dictionaries cannot contain duplicate keys but can contain duplicate values since each value has unique key.

Related Videos