Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Zip and Sort Functions | Functions
Introduction to Python (generated task tests)

Swipe to show menu

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.

Task

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:

Requirements checklist

  1. Check that combined_list is a list of tuples, where each tuple contains a product name, its corresponding price, and quantity sold, zipped from the original lists.
  2. Check that sorted_products is a list of tuples sorted in ascending order by product name.
  3. Check that the first tuple in sorted_products has the product name "Apple", and its price and quantity sold match the original lists for "Apple".
  4. Check that the second tuple in sorted_products has the product name "Banana", and its price and quantity sold match the original lists for "Banana".
  5. Check that the third tuple in sorted_products has the product name "Cherry", and its price and quantity sold match the original lists for "Cherry".
  6. Check that the fourth tuple in sorted_products has the product name "Mango", and its price and quantity sold match the original lists for "Mango".
  7. Check that the program prints four lines, each containing the correct product name, price, and quantity sold in the specified format.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 6. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 2.17

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.

Task

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:

Requirements checklist

  1. Check that combined_list is a list of tuples, where each tuple contains a product name, its corresponding price, and quantity sold, zipped from the original lists.
  2. Check that sorted_products is a list of tuples sorted in ascending order by product name.
  3. Check that the first tuple in sorted_products has the product name "Apple", and its price and quantity sold match the original lists for "Apple".
  4. Check that the second tuple in sorted_products has the product name "Banana", and its price and quantity sold match the original lists for "Banana".
  5. Check that the third tuple in sorted_products has the product name "Cherry", and its price and quantity sold match the original lists for "Cherry".
  6. Check that the fourth tuple in sorted_products has the product name "Mango", and its price and quantity sold match the original lists for "Mango".
  7. Check that the program prints four lines, each containing the correct product name, price, and quantity sold in the specified format.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

close

Awesome!

Completion rate improved to 2.17

Swipe to show menu

some-alt