Professional Documents
Culture Documents
Xi Ip (19.09.23)
Xi Ip (19.09.23)
2. How are objects stored in dictionaries different? Ans. The objects or values stored in a dictionary
can be of any data type (even the type NONE) but keys can b immutable type-objects, e.g., strings,
integers, etc.
[HOTS
>>> di = dict()
4. Can sequence operations such as slicing and concatenation be applied to dictionaries? Why/Why
not? [HOTS
Ans. No, sequence operations such as slicing and concatenation cannot be applied to dictionaries as
dictionary is not a sequence. Since they are not maintained in any specific order or we may say
arranged in the order of insertion, operations that depend on a specific order cannot be used.
However, we can use some dictionary methods to achieve similar functionality. For example,
items() functions returns a sequence-like object that can be iterated over, sliced and concatenated.
[HOTS] Ans. Lists cannot be used as keys in a dictionary because they are mutable and a Python
dictionary can have only
keys of immutable types. 6. If the addition of a new key-value pair causes the size of the dictionary
to grow beyond its original size, it
shall result in an error. True or false? [HOTS Ans. False. No error shall occur because dictionaries
are mutable in nature and they can grow or shrink as and when required.
Ans. In list, elements are enclosed within square brackets whereas in dictionary key-value pairs are
enclosed within curly braces. In dictionary, index value can be of any data type (except list) and is
called key. but in list, index value is an integer. (2x2=4)
III. Explain the following (4x4=16)
1. Suppose L = [“These”,”are”,”a”,[“few”,”word”],”that”,”we”,”will”,”use”]
consider the above list and answer the following:
a) L[3:4]
b) L[3:4][0][1]
c) L[0::2]
d) L[4:]
3. Write a python code to find atleast one common element amongst the two inputted list.
4. Explain about different built-in functions in the list.