Function below does make a copy of given data.
def copyA(data): acopy =  for d in data: acopy.append(d) return acopy
But when I use it in an another function it does return anything. Can anybody tell me what's wrong and how can I fix it?
def selection_sort(unsorted): result = list() acopy= for d in unsorted: acopy.append(d) return acopy while len(acopy) > 0: out = min(acopy) acopy.remove(out) result.append(out) return result print(result)
return stops the function it is placed in as soon as it is encountered, hence
selection_sort does not reach the
while loop. If you delete
return acopy it should work as expected
Admin | 3 months ago