Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions