Computer Science, asked by megha20052002agrawal, 10 months ago

Start with the list[8,9,10]. Do the following using list functions
(a) Set the second entry (index 1) to 17
(b) Add 4, 5 and 6 to the end of the list.
(c) Remove the first entry from the list.
(d) Sort the list.
(e) Double the list.
(f) Insert 25 at index 3

Answers

Answered by Anonymous
14

Hey mate....

here's the answer...

# Python code to demonstrate the working of

# del and pop()

# initializing list

lis = [2, 1, 3, 5, 4, 3, 8]

# using del to delete elements from pos. 2 to 5

# deletes 3,5,4

del lis[2 : 5]

# displaying list after deleting

print ("List elements after deleting are : ",end="")

for i in range(0, len(lis)):

print(lis[i], end=" ")

print("\r")

# using pop() to delete element at pos 2

# deletes 3

lis.pop(2)

# displaying list after popping

print ("List elements after popping are : ", end="")

for i in range(0, len(lis)):

print(lis[i], end=" ")

Hope it helps you ❤️

Answered by Anonymous
4

Here is Your Answer

1. del[a : b] :- This method deletes all the elements in range starting from index ‘a’ till ‘b’ mentioned in arguments.

1. del[a : b] :- This method deletes all the elements in range starting from index ‘a’ till ‘b’ mentioned in arguments.2. pop() :- This method deletes the element at the position mentioned in its arguments.

# Python code to demonstrate the working of

# del and pop()

# initializing list

lis = [2, 1, 3, 5, 4, 3, 8]

# using del to delete elements from pos. 2 to 5

# deletes 3,5,4

del lis[2 : 5]

# displaying list after deleting

print ("List elements after deleting are : ",end="")

for i in range(0, len(lis)):

print(lis[i], end=" ")

3. insert(a, x) :- This function inserts an element at the position mentioned in its arguments. It takes 2 arguments, position and element to be added at respective position.

Hope it Heplfull Answer

Similar questions