Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Task: Sorting Data | Lists, Loops And Functions
Python: For Beginners
Avsnitt 2. Kapitel 3
single

single

Task: Sorting Data

Svep för att visa menyn

Now that you master closures, let's sort some data.

Sorting data is a key skill. Here's how to use sorted():

123
data = [5, 2, 8, 1] result = sorted(data) print(result) # Printing the result

In Python, the sorted() function returns a new list and doesn't modify the original. it's a pure function.

Uppgift

Svep för att börja koda

We need you to sort the list numbers in ascending order and store the result in sorted_numbers.

  • Assign the sorted version of numbers to the variable sorted_numbers;
  • Use the sorted function to do this;
  • Print sorted_numbers.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 3
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt