Question
Scenario Given the following challenges,use append(), extend(), pop(), and insert()tochange the contents of the lists. Aim The aim of this activity is to get acquainted
Scenario
Given the following challenges,use append(), extend(), pop(), and insert()tochange the contents of the lists.
Aim
The aim of this activity is to get acquainted with list methodsby utilizing various Python list methods.
Using the ipython3 interactive shell, change thecontents of this list using the various available methods.
Steps for Completion
Suppose that we have the following list:
Strawberry, Blueberry, Blackberry, Cranberry
Define the list berries with the following elementsshown in Snippet 5.11:
Strawberry, Blueberry, Blackberry, Cranberry
Snippet 5.11
Change the contents of this list using the various availablemethods:
Note: Check your output by calling the list after eachmethod
Using the built-in append() method, add thevalue Raspberry to the list berries.
Using the built-in extend() method, extend anempty fruits list from the berries list thatyou created previously.
Insert Mangoes into the fruits list atindex 2 using the built-in method insert().
Remove the element at index 1 fromthe fruits list using the built-inmethod pop() and replace it with Apples, usingthe insert() built-in method.
Finally, sort the elements in the fruits list by usingthe built-in method sort() with keyword arguments. Setthe key argument to None andthe reverse argument to False.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started