@MathiasRa, your code will not work as append()
method doesn't return any list.
Previous answers are appreciated. So can directly get your merged list [0, 1, 2, 3]
using the below line.
list1 = [3]
list2 = [i for i in range(3)]
newlist = sorted(list1 + list2)
print (newlist) # [0, 1, 2, 3]
» If you don't want updated list as return value
Use extend() method in place of append() as follows:
Note: In this case, you won't get anything returned like append(). The statement will update the calling list (list1) by appending all items of passing list (list2).
list1 = [3]
list2 = [i for i in range(3)]
list1.extend(list2)
print(list1) # [3, 0, 1, 2]
print(sorted(list1)) # [0, 1, 2, 3]