list1 = [2,5,4,6,3,8,9,7,1]
list2 = [-4,5,-3,8,-7,2,5,1,3,6]
def maxFunction(attrList,attrList2):
value1 = attrList[0]
for item in attrList:
if item <= value1:
value1 = item
attrList2.append(value1)
attrList.remove(value1)
if len(attrList)> 0:
maxFunction(attrList,attrList2)
return attrList2 #I tried to else:
# return attrList2
print(maxFunction(list2, []))
above code works fine. But I have a question about this function. If I put the return statement behind an else statement(would be logical as I used an if statement), it does print the list but it no longer returns it. Can someone explain why as I'm quite new to programming. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire