def minimizeMaximumPair(lst):
lst.sort()
def compute(aList):
if len(aList) != 0:
return [(aList[0], lst[len(aList) - 1])].extend(compute(aList[1:len(aList) - 1]))
return []
return compute(lst)
When I get the the last recursion step I get an
TypeError: 'NoneType' object is not iterable
I tried returning nothing, and a []
The issue is when you call .extend().
Your compute function tries to return the value of .extend(), which is None. Similar to .sort(), .extend() modifies the object itself, rather than returning a modified copy of the object. This is known as mutability. Here's some working code:
def compute(aList):
if len(aList) != 0:
out = [(aList[0], lst[len(aList) - 1])]
out.extend(compute(aList[1:len(aList) - 1]))
return out
return []
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With