Osio 2. Luku 3
single
Task: Sorting Data
Pyyhkäise näyttääksesi valikon
Now that you master closures, let's sort some data.
Sorting data is a key skill. Here's how to use sorted():
123data = [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.
Tehtävä
Pyyhkäise aloittaaksesi koodauksen
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.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 3
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme