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

single

Task: Sorting Data

Sveip for å vise menyen

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.

Oppgave

Sveip for å begynne å kode

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 desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt