Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python methods. #Return True if the list is decreasing. False otherwise. A list

ID: 3837788 • Letter: P

Question

Python methods. #Return True if the list is decreasing. False otherwise. A list is decreasing if each element # in it is strictly less than the element before it. An empty list or a list with one element is assumed # to be decreasing. def is_decreasing(self): As an example, calling the method on linked list with the values 12 9 8 4 3 2 should return True, while the list 9 8 7 7 4 3 1 would cause the method to return False. Removes sequences of two or more repeating values in the list. The method #should modify the list, but should NOT return or output anything. def remove_reps(so1f): As an example, calling the method on the linked list with the values 3 4 4 5 6 6 6 4 would modify the list to 3 5 4. Calling the method on the linked list 4 3 2 5 4 would keep the list unchanged. Calling the method on the linked list 5 5 5 would remove all elements. Modify method main to test these methods.

Explanation / Answer


#Program for Method is_decreasing:

def is_decreasing(self):
for i in range(len(self) - 1):
if self[i]<self[i+1]:
return False

return True
  
# Program for Method remove_reps

def remove_reps(self):
i = 0
dupe = False
while i < len(self)-1:
if self[i] == self[i+1]:
del list[i]
dupe = True
elif dupe:
del list[i]
dupe = False
else:
i += 1
  
#main method code

mylist = [12,9,8,4,3,2];
result = is_decreasing( mylist );
print "Result: ", result

list = [3,4,4,5,6,6,4]
remove_reps(list)