ca0ed347-54d5-4ff2-ae50-828f4b10614a
ca0ed347-54d5-4ff2-ae50-828f4b10614a
ca0ed347-54d5-4ff2-ae50-828f4b10614a
Unit -2 (8m):
Explain the different ways to create a dictionary in python.
In Python, there are several ways to create a dictionary. Here are some
examples:
1 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
1. Lists:
• Lists are ordered, which means the items in the list have a
specific order and can be accessed by index.
2. Tuples:
• Tuples are ordered, which means the items in the tuple have a
specific order and can be accessed by index.
2 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
3. Dictionaries:
In summary, lists and tuples are similar in that they are ordered and
can be accessed by index, but lists are mutable while tuples are
immutable. Dictionaries are different from lists and tuples in that they
use key-value pairs and are unordered.
(a) Explain the use of the zip ( ) function in python?
(b) Explain packing and unpacking in python?
3 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
Packing and unpacking can be used with other data structures as well,
such as lists and dictionaries.
(a) Explain the various operations that can be performed on lists in
python?
(b) Discuss the built–in functions used on dictionaries with
examples?
(a) Lists are a fundamental data structure in Python, and there are
several operations that can be performed on them. Some of the
commonly used operations include:
4 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
5 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
Example:
Example:
Example:
Example:
(b) A frozen set is a set that is immutable i.e. we cannot change the
6 of 13 12-12-2023, 19:10
Unit -2 (8m): https://awaisahmed.notion.site/Unit-2-8m-07957688c19d43eea4460e4e...
(b) A frozen set is a set that is immutable i.e. we cannot change the
elements in a frozen set after it is created. We can create a frozen set
using the frozenset() function. Here is an example:
7 of 13 12-12-2023, 19:10