Lists, Dictionaries and Tuples Assignment
Lists, Dictionaries and Tuples Assignment
Assignment
INSTRUCTIONS: This is an individual work for practice purposes. Avoid using
generative AI and submitting work that looks-alike.
Submit your work by email to [email protected] before 1st Nov, 2024
SECTION (A)
Question 1:
How many types of built-in types of sequences in Python.
Question 2:
Write the output of the given Python code. (Add a screenshot of your output)
# !/user/bin/python
list1 = [‘physics’, ‘chemistry’, 1997, 2000];
list2 = [1,2,3,4,5,6, 7];
print “list1[0]”, list1[0]
Question 3:
Write the output of the given Python code. (Add a screenshot of your output)
# !/user/bin/python
listl = [‘physics’, ‘chemistry’, 1997,2000];
list2 = [1,2, 3,4,5, 6, 7];
print “list2[l:5[ :”, list2[l:5]
Question 4:
How can we remove list element ?
Why we use cmp(listl, list2) in Python?
Question 6:
What is the use of len(list)) in Python?
Question 7:
Describe max(list) method.
Question 8:
Describe min(list) method.
Question 9:
What is the use of list(seq) in Python ?
Question 10:
What do you mean by list.append(obj)
Question 11:
What do you mean by list.count(obj)
Question 12:
Explain list.extend(seq)
Question 13:
Is list.reverse() method return a value?
Question 14:
Which method is used to sort objects of list.
Question 15:
Which function is used to reverse objects of list in place.
Question 16:
Which function is use for removing object obj from list.
Question 17:
Which function is use for returning the lowest index in list that obj appears.
SECTION (B)
Question 1:
Using example, Define list in Python. lists (Add a screenshot of your output)
Question 2:
Give an example to access values in lists lists (Add a screenshot of your output)
Question 3:
Give an example to update single or multiple elements of lists (Add a screenshot of your
output)
Question 4:
Give an example to remove list element. (Add a screenshot of your output)
Question 5:
Describe list() with its syntax.
Question 6:
Write the output of the given Python code : (Add a screenshot of your output)
#!/user/bin/python
list1, list2 = [123, ‘xyz’], [456, ‘abc’]
print cmpt(list1,
list2); print
cmp(list2, list1); list3
= list2 + [786]; print
cmp(list2, list3)
Question 7:
Write the output of the given Python code :
#!/user/bin/python
aList = [123, ‘xyz’, ‘zara’, ‘abc’, 123];
bList = [2009, ‘manni’];
aList.extend (bList)
print “Extended List :”, aList;
Question 8:
Write the output of the given python code :
# ! ‘user/bin’pvthon
aList1 = [123, ‘xvz’, zara’, abc’];
print “Index for xyz : ” aList. index) ‘xyz’);
print “Index for zara :”, aList. index(‘zara’);
Question 9:
Write the output of the given python code :
# !/user/bin/python
aList = [123, ‘xyz’, ‘zara’, ‘abc’];
aList.insert (3,2009) print “Final List:”, aList
Question 10:
Write the output of the given python code :
#!/user/bin/python
aList1 = [123, ‘xyz’, ‘zara’, ‘abc’];
aList.insert (3,2009) print “Final Lista List
Question 11:
Write the output of the given python code :
# !/user/bin/python
aList1 = [123, ‘xyz’, ‘zara’, ‘abc’];
print “A List:”, aList.pop()
print “B List:”, aList.pop(2)
Question 12:
Write the output of the following code
A = [2, 4, 6, 8,10] L
= len (A)
S=o
for I in range (1, L, 2): S
+ = A[I]
print “Sum=”, S
Question 13:
How are lists different from strings when both are sequences ?