Computer Science, asked by manoj30061972, 28 days ago

Consider the list L1=[15,25,35,40] write statements to perform the following?

a) To display maximum value from the list L1

b) To remove 3rd element from the list L1

c) To add [30,40,50] towards the end of the given list L1

d) Double the elements of the list L1

e) To print sorted list L1 in ascending order​

Answers

Answered by Equestriadash
23

Given list:

L1 = [15, 25, 35, 40]

a) To display the highest element.

  • print(L1.max())

b) To remove the 3rd element.

  • L1.pop(2)
  • L1.remove(35)
  • del L1[2]

c) To add [30, 40, 50] to the end of L1.

  • L1.extend([30, 40, 50])

d) To double the elements in L1.

  • for i in range(len(L1)):

      L1[i] = L1[i]*2

e) To sort L1 and print it in ascending order.

  • print(sorted(L1, reverse = True))

  • max() is a function that retrieves the highest elements from a list.
  • pop() is a method that removes an element by specifying the index position. remove() is a method that removes the specified element. del is a function that deletes an element by specifying its index position.
  • sorted() is a method that sorts the list in ascending order [by default]. It is used only for display purposes and will not permanently sort the list.
Similar questions