Question
extract_negatives: The first argument, xs , contains integers. We will be removing any negative integers we find in xs , and appending them to the
extract_negatives: The first argument, xs, contains integers. We will be removing any negative integers we find in xs, and appending them to the second argument, new_home. A reference to the list that received negatives must be returned. When no second argument is given, a list of all the extracted negatives should be created and returned.
o Figuring out the signature of this function is part of the task. Careful: What default value do you want to use for new_home? What happens when we call the function multiple times in the same coding session? (try it out)
o Go ahead and use methods like .insert(), .pop(), .append()
o You might need to iterate and update the list at the same time. Hint: if you need to traverse a list from front to back, but you don't always want to go to the next index location, while loops can be very useful we get to control when (which iteration) to step forward.
Examples:
o >>> xs = [1,-22,3,-44,-5,6,7]
>>> extract_negatives(xs)
[-22, -44, -5] #return a list of negatives
>>> xs [1, 3, 6, 7] #remove negatives from xs
o >>> xs = [1,-22,3,-44,-5,6,7]
>>> negatives = [-3, -1]
>>> extract_negatives(xs, negatives)
[-3, -1, -22,-44,-5]
>>> negatives
[-3, -1, -22,-44,-5] #new negatives appended to the list
>>> xs
[1, 3, 6, 7]
use python3 languag
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