Start with the list[8,9,10]. Do the following using list functions
6
(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
2
Answer:
Assume that the list is,
l = [8,9,10]
- To set second entry to 17, write this - l[1] = 17. It replaces the element at second index with the value 17.
- To add 4,5,6 to the end of the list, write - l.extend([4,5,6]). The extend() function of list adds a list at the end of list.
- To remove the first element from the list, write - del(l[0]). The del() function deletes a variable or an element from list. Since, index of the first element is 0, so, it deletes first element.
- To sort the list, write - l.sort(). The sort function sorts a given list.
- To double the list, we can write - l = l * 2 or we can also solve using extend function - l.extend(l).
- To insert 25 at index 3, write - l.insert(3,25). The insert() function inserts an element at specific index.
Similar questions