Python Tip of the Day: Sort Lists with sorted()
Sort Lists with sorted()
Author: Jeremy Morgan
Published: November 21, 2024
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.
Need a sorted version of a list without altering the original? sorted()
is your friend.
# Sorting a list
numbers = [5, 2, 9, 1]
sorted_numbers = sorted(numbers)
print(sorted_numbers) # Output: [1, 2, 5, 9]
print(numbers) # Original list remains unchanged
The Python Tip of the Day is a daily series published in the month of November. The tips are designed to help you become a better Python programmer. I post tips like this and more every single day on X. Let’s connect!
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.