Computer Science, asked by gulshankumarvarma97, 2 months ago

write the most appropriate list method to perform the following tasks.(2)

a. delete a given element from the list

b. delete 3 rd element from the list

c. add an element in the end of the list

d. add an element in the beginning of the list​

Answers

Answered by rohithspacejet
20

Answer:

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.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.

4. remove() :- This function is used to delete the first occurrence of number mentioned in its arguments.5. sort() :- This function sorts the list in increasing order.

6. reverse() :- This function reverses the elements of list.

7. extend(b) :- This function is used to extend the list with the elements present in another list. This function takes another list as its argument.

8. clear() :- This function is used to erase all the elements of list. After this operation, list becomes empty.

Explanation:

gulshan its me rohith from your school dont worry keep it up

Answered by kartavyaguptasl
1

Answer:

The answers to the appropriate list methods/functions to perform the given tasks:

(a) remove function

(b) .pop( ) function

(c) .append( ) function

(d) .insert( ) function

Explanation:

In Python, an inventory is created by placing elements inside square brackets [ ], separated by commas. an inventory can have any number of items and they may be of different types (integer, float, string, etc.). an inventory can also have another list as an item. this is often called a nested list.

Some important basic functions for lists:

  • We can use remove() to delete the given item or pop() to delete an item at the given index.
  • The pop() method removes and returns the last item if the index isn't provided. This helps us implement lists as stacks (first in, last out stay data structure).
  • Python List insert() method inserts a given element at a given index during a list using Python.
  • The append() method appends a component to the end of the list.

#SPJ3

Similar questions