I am learning python. I am supposed to create a function with two parameters. The first of which must be a list and the second an integer. If its not an integer, it must assert an error. the list must add the integer and then sort it out in ascending order. The list passed through the first parameter must be modified but cannot be returned. I am stuck. I dont know how to achieve this without return. Dont give me the answer, just point me in the right direction.
def my_insert(lista, num):
assert (type(num) is int)
lista.append(num)
lista = sorted(lista)
l = [1, 3, 5]
my_insert(l, 4)
print(l)
the print should print [1, 3, 4, 5] and not [1, 3, 5, 4]
lista = sorted(lista)
to belista.sort()
?isinstance(x, y)
rather thantype(x) is y
for polymorphism and duck-typing reasons. You should be able to find more details elsewhere. Good luck.