Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get this code to output a sorted list instead of "none"

Codecademy problem#5 "Combine Sort"

def combine_sort(lst1, lst2):
  combined = lst1 + lst2
  return combined.sort()

print(combine_sort([1,3,2],[3,1,2]))

This code outputs

none

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could try this instead (once you realize the subtle difference between sorted(L) and L.sort()).

>>> def combined_sort(L1, L2):
    return sorted(L1 + L2)

>>> L1 = [1, 3, 2]
>>> L2 = [5, 9, 6]
>>> combined_sort(L1, L2)
[1, 2, 3, 5, 6, 9]
>>> 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading