Guess the signature using a default value that is complex D

Guess the signature, using a default value that is complex. # Define a function called relocate_evens(). The first argument, data, # is a list of integers. We will be removing any evens we find in data, and # appending them to the second argument, new_home. # - A reference to the list which received any evens must be returned. # - When no second argument is given, a list of all the relocated evens # should be created and returned. # - 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? # def relocate_evens(): # You need to fix this signature line first # return \"not implemented yet\"

Solution

def relocate_evens(data,new_home=[]): # set the default value of new_home to []
for i in data:
if(i%2==0): # if even
new_home.append(i); # append element to new_home
for i in new_home:
data.remove(i)
return new_home
data = [1,2,3,4,5]
print relocate_evens(data)
print relocate_evens([6,7,8,9,10])

# sample output

# [2,4,6, 8,10]

 Guess the signature, using a default value that is complex. # Define a function called relocate_evens(). The first argument, data, # is a list of integers. We

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site