Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Zip and Sort Functions | Functions
Introduction to Python (copy)
course content

Kursusindhold

Introduction to Python (copy)

Introduction to Python (copy)

1. Getting Started
2. Variables and Types
3. Conditional Statements
4. Other Data Types
5. Loops
6. Functions

book
Challenge: Zip and Sort Functions

We still have a few functions from the previous chapter to cover, so let's get some practice with them.

Recall the zip() function, which is particularly useful when working with multiple related lists. This function allows you to manage different properties of items simultaneously, such as sorting products while maintaining their associated attributes.

Opgave

Swipe to start coding

You got three lists: product names, prices, and quantities sold. Your goal is to organize, sort, and display this data in a specific format.

Code Instructions

  • Use zip() to combine the three lists into a list of tuples in the order: (product_name, price, quantity_sold). Assign the result to combined_list.
  • Use sorted() to sort combined_list by product name in ascending order. Assign the sorted result to sorted_products.
  • Loop through sorted_products and print each product's name, price, and quantity sold using the specified format.

Output Requirements

For each product, print:

python

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 6. Kapitel 2
toggle bottom row

book
Challenge: Zip and Sort Functions

We still have a few functions from the previous chapter to cover, so let's get some practice with them.

Recall the zip() function, which is particularly useful when working with multiple related lists. This function allows you to manage different properties of items simultaneously, such as sorting products while maintaining their associated attributes.

Opgave

Swipe to start coding

You got three lists: product names, prices, and quantities sold. Your goal is to organize, sort, and display this data in a specific format.

Code Instructions

  • Use zip() to combine the three lists into a list of tuples in the order: (product_name, price, quantity_sold). Assign the result to combined_list.
  • Use sorted() to sort combined_list by product name in ascending order. Assign the sorted result to sorted_products.
  • Loop through sorted_products and print each product's name, price, and quantity sold using the specified format.

Output Requirements

For each product, print:

python

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 6. Kapitel 2
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt