Define a function sort which accepts only a numeric comparison predicate and a l
ID: 3864594 • Letter: D
Question
Define a function sort which accepts only a numeric comparison predicate and a list of numbers as arguments, in that order, and returns the list of numbers sorted by the predicate. Follow Design Guidelines Four, Five, and Six completely. A > (sort (sort '(3)) 5 (3) 6 7 > (sort (sort (sort (sort > '()) 17 () 18 19 > (sort > '(1)) 20 (1) 21 22 > (sort > '(1 2)) 23 (2 1) 24 25 > (sort > '(1 2 3)) 26 (3 2 1) 27 28 > (sort > '(1 2 3 4 5 6 7 8 9)) 29 (9 8 7 6 5 4 3 2 1)Explanation / Answer
sorting.py
def sort(sign, alist):
if sign == '<':
return sorted(alist)
elif sign == '>':
return sorted(alist, reverse = True)
print(sort('<', (1, 2, 3, 6, 4)))
print(sort('>', (1, 2, 3, 6, 4)))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.