Problem: Write a function that accepts a list of integers and return a list that is the drawn version (of ascending order) of the original list. (Original list should not be modified). You can not use the built-in sort () or sorted () function.
Here's my solution:
1 def func(i):
2 i_copy = []
3 for elem in i:
4 i_copy.append(elem)
5 for y in range(0, len(i_copy)):
6 for x in i_copy:
7 if x < i_copy[y]:
8 aux = x
9 i_copy[y] = x
10 i_copy = aux
11 return i_copy
It gives the following error:
Error in evaluating function: TypeError at line 7 'int' object has no attribute ' getitem '
Does anyone help me solve the problem?
I do not understand why the __getitem__
attribute has to do with the problem or why I need it, and why this particular line is wrong.