1
Problem: Write a function that accepts a list of integers and returns a list that is the drawn (ascending) version of the original list.(Original list should not be modified). You cannot use the built-in Sort() or Sorted function().
This is 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
Gives the following error:
Error in evaluating Function: Typeerror at line 7 int' Object has no attribute 'getitem'
Someone help me solve the problem?
I don’t understand why the attribute __getitem__
has to do with the problem or why I need it, and why this particular line is wrong.
Thanks for your help, but it’s not right. For the following input: func ( [1256, 0, 2, -3, 4, 10, 7, 8, 9] ) should exit the following output: [-3, 0, 2, 4, 7, 8, 9, 10, 1256], but instead leaves: [9, -3, -3, -3, -3, 9, -3, -3]
– Inês Barata Feio Borges
gives a look at this sort code. https://pt.wikipedia.org/wiki/Bubble_sort
– Brumazzi DB