Quesiton between the two queries Python


#1
def combine_sort(lst1, lst2):
  unsorted = lst1 + lst2
  sortedList = sorted(unsorted)
  return sortedList

print(combine_sort([4, 10, 2, 5], [-10, 2, 5, 10]))

def combine_sort(lst1, lst2):
  new = lst1.append(lst2)
  new2 = sorted(lst1)
  return new2

#Uncomment the line below when your function is done
print(combine_sort([4, 10, 2, 5], [-10, 2, 5, 10]))

Hello For exeszise what would be the difference between the teo querries will both of them work ?


#2

if i run the second example, i get an error.

we can see why:

def combine_sort(lst1, lst2):
  new = lst1.append(lst2)
  print(new)
#  new2 = sorted(lst1)
#  return new2

#Uncomment the line below when your function is done
print(combine_sort([4, 10, 2, 5], [-10, 2, 5, 10]))

see? You now created a nested list, not ideal for sorting if the result should be a single list at the end