0% found this document useful (0 votes)
98 views

Chapter 11 Assignment

This document contains questions about list manipulation in Python. It asks about differences between lists and strings, list methods like append() and extend(), determining list size, concatenating and sorting lists, nested lists, splitting strings into lists, finding the maximum value and its index in a list, modifying lists, multiplying lists, inserting elements into lists, and counting elements in a list. It also asks about mutability and "in place" memory updates in Python lists.

Uploaded by

sainothegamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Chapter 11 Assignment

This document contains questions about list manipulation in Python. It asks about differences between lists and strings, list methods like append() and extend(), determining list size, concatenating and sorting lists, nested lists, splitting strings into lists, finding the maximum value and its index in a list, modifying lists, multiplying lists, inserting elements into lists, and counting elements in a list. It also asks about mutability and "in place" memory updates in Python lists.

Uploaded by

sainothegamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CHAPTER-11 ASSIGNMENT

LIST MANIPULATION
Q1. How are lists different from strings when both are sequences?
Q2. Write difference between append( ) and extend( ) methods of list.
Q3. How we can determine the size of the list?
Q4. Can we concatenate two lists? How?
Q5. How we can sort the elements of the list?
Q6. What are nested lists?
Q7. What is the output when we execute list(“hello”)?
Q8. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
Q9. Suppose list1 is [12, 323, 2322, 14, 25], what is list1[:-1] ?
Q10. What is the output when following code is executed?
A. >>>names = ['Freya', 'Mohak', 'Mahesh', 'Dwivedi']
>>>print(names[-1][-1])

B. names1 = ['Freya', 'Mohak', 'Mahesh', 'Dwivedi']


names2 = names1
names3 = names1[:]
names2[0] = 'Vishal'
names3[1] = 'Jay'
sum = 0
for ls in (names1, names2, names3):
if ls[0] == ' Vishal ':
sum += 2
if ls[1] == ' Jay ':
sum += 5
print(sum)

C. >>>"Welcome to Computer Science".split()

D. List = [1, 5, 5, 15, 5, 1]


max = List[0]
indexOfMax = 0
for i in range(1, len(List)):
if List[i] > max:
max = List[i]
indexOfMax = i
print(indexOfMax)

E. list1 = [11, 13]


list2 = list1
list1[0] = 14
print(list2)

Page 1 of 2
F. names1 = ['Freya', 'Mohak', 'Mahesh', 'Dwivedi']
if 'freya' in names1:
print(1)
else:
print(2)

G. numbers = [11, 12, 13, 14]


numbers.append([15,16,17,18])
print(len(numbers))

H. values = [[13, 41, 15, 11 ], [313, 16, 11, 12]]


for r in values:
r.sort()
for element in r:
print(element, end = " ")
print()

I. points = [[1, 20.5], [2, 1.5], [0.5, 0.5]]


points.sort()
print(points)

J. a=[101,123,561,[178]]
b=list(a)
a[3][0]=915
a[1]=134
print(b)

K. a=[132,526,127]
a.append([827])
a.extend([425,627])
print(a)

Q11. Suppose list1 is [9, 1, 3, 2], what is list1 * 2?


Q12. To add a new element to a list we use which command?
Q13. To insert 9 to the second position in list1, write its command?
Q14. Suppose list1 is [1, 3, 5, 12, 5], what is list1.index(5)?
Q15. Suppose list1 is [13, 14, 15, 20, 15, 25, 11, 13], what is list1.count(15) ?
Q16. Given a list of integers, L, write code to calculate and display the sum of all the odd numbers in
the list.
Q17. Given two lists, write a program that prints “Overlapped” if they have at least one member in
common otherwise prints “Separated”.
Q18. What do you understand by mutability? What does “in place” memory updation mean?

Page 2 of 2

You might also like