Assignment 3
Assignment 3
2 Marks
1. Can we delete list elements? Justify your answer.(CO3)
2. Define tuple in python? How to create and access it? (CO3)
3. Compare list and tuple. (CO3)
4. Enlist built in function in dictionaries and explain any two. (CO3)
5. Explain any two built in methods of set in python with example(CO3)
4 Marks
1. Describe basic operations perform on list with example. (CO3)
2. Explain any four built in methods of lists in python with example. (CO3)
3. Explain the basic operations that can be performed on tuple. (CO3)
4. Enlist built in function in tuple and explain any four. (CO3)
5. Explain the basic operations that can be performed on set in python with
suitable example(CO3)
6. Explain the basic dictionaries operations with an example. (CO3)
Descriptive Question:
1. How to declare the list? Can we change or update the list elements? Justify
your answer.
2. Write a short note on slicing list.
3. Explain the following function w.r.t list
a) append() b) insert()
4. Can we delete the list element?
5. Explain the use of keywords del w.r.t list.
6. How to declare the tuple? Can we change or update the tuple? Justify your
answer.
7. How to declare the set? Can we change iterate through set by using while
loop? Justify
your answer.
8. Can we iterate through set by using for loop? Justify your answer.
9. Can we add new elements in set? Justify your answer with example.
10. Explain the following set operations
a) Set union b) Set intersection c) Set symmetric difference
11. How to declare the dictionary in python?
12. Explain use of update() function w.r.t dictionary.
13. Explain how to access dictionary element using index/key with example.
14. Explain different ways and function to remove key:value pair from
dictionary.
MCQ Question:
1. If a={5,6,7}, what happens when a.add(5) is executed?
a) a={5,5,6,7}
b) a={5,6,7}
a) { } b) set()
c) [ ] d) ( )
3. Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]]) b) set([1,2,2,3,4])
c) set((1,2,3,4)) d) {1,2,3,4}
a) [1, 2, 3] b) (1, 2, 3)
c) {1, 2, 3} d) {}
>>>t[1:3]
a) (1, 2) b) (1, 2, 4)
c) (2, 4) d) (2, 4, 3)
>>> a=(0,1,2,3,4)
>>> b=slice(0,2)
>>>a[b]
c) (0,1) d) (0,2)
>>> a=(1,2,3,4)
>>>del a
>>> a=(2,3,4)
>>>sum(a,3)
>>> a=("Check")*3
>>>a
c) (2,3,4) d) (2,3)
>>> a=(2,3,1,5)
>>>a.sort()
>>>a
a) (1,2,3,5) b) (2,3,1,5)
14. The ____ function removes the first element of a set and the last element of
a list.
a) remove b) pop
c) discard d) dispose
15. The difference between the functions discard and remove is that:
a) Discard removes the last element of the set whereas remove removes the first
b) Discard throws an error if the specified element is not present in the set
whereas
remove does not throw an error in case of absence of the specified element
c) Remove removes the last element of the set whereas discard removes the first
d) Remove throws an error if the specified element is not present in the set
whereas discard does not throw an error in case of absence of the specified
element
16. If we have two sets, s1 and s2, and we want to check if all the elements of s1
are present
a) s2.issubset(s1) b) s2.issuperset(s1)
c) s1.issuperset(s2) d) s1.isset(s2)
s1.issubset(s1)
a) True b) Error
c) No output d) False
18. Which of the following functions will return the symmetric difference
between two sets,
x and y?
a) x | y b) x ^ y
c) x& y d) x – y
19. What will be the output of the following Python code snippet?
z=set('abc')
z.add('san')
z
a) {‘abc’, ‘p’, ‘q’, ‘san’} b) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
c) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’} d) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
20. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in
reverse order,
a) reverse(l) b) list(reverse[(l)])
c) reversed(l) d) list(reversed(l))
21. Which of the following functions will not result in an error when no
arguments are
passed to it?
a) min() b) divmod()
c) all() d) float()
a) ord() b) ord(‘ ‘)
c) ord(“) d) ord(“”)
len(["hello",2, 4, 6])
a) 4 b) 3
c) Error d) 6
a) (x*y)*z b) (x**y) / z
c) (x**y) % z d) (x**y)*z
all([2,4,0,6])
a) Error b) True
c) False d) 0
import math
abs(math.sqrt(25))
a) Error b) -5
c) 5 d) 5.0
round(4.5676,2)?
a) 4.5 b) 4.6
c) 4.57 d) 4.56
29. If a is a dictionary with some key-value pairs, what does a.popitem() do?
30. What will be the output of the following Python code snippet?
a = {}
a[1] = 1
a['1'] = 2
a[1]=a[1]+1
count = 0
for i in a:
count += a[i]
print(count)
b) 2
c) 4
d) 1
31. What will be the output of the following Python code snippet?
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>>b.most_common(1)
c) {1,”A”,2”B”} d) { }
34. To which of the following the “in” operator can be used to check if an item
is in it?
a) Lists b) Dictionary
def example(L):
'''
i=0
result = []
while i <len(L):
result.append(L[i])
i=i+3
return result
d) Return a list containing the items from L starting from index 0, omitting
every
third item
36. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error b) None
c) 25 d) 2
a) list1.shuffle() b) shuffle(list1)
c) random.shuffle(list1) d) random.shuffleList(list1)
print(sum(lst,[]))
a) [[3],[7]] b) [1,2,3,4]
c) Error d) [10]
39. Which of the following functions does not necessarily accept only
iterablesas
arguments?
a) enumerate() b) all()
c) chr() d) max()
chr(‘97’)
chr(97)
a)a
Error
b)‘a’
c)Error
d)Error
Error