0
0
Kotlinprogramming~15 mins

Zip for combining collections in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Zip for combining collections
📖 Scenario: You are organizing a small event and have two lists: one with the names of guests and another with their favorite drinks. You want to pair each guest with their favorite drink to prepare the right refreshments.
🎯 Goal: Build a Kotlin program that uses zip to combine two lists into pairs of guest names and their favorite drinks.
📋 What You'll Learn
Create a list called guests with the exact names: "Alice", "Bob", "Charlie"
Create a list called drinks with the exact drinks: "Coffee", "Tea", "Juice"
Create a variable called guestDrinkPairs that uses zip to combine guests and drinks
Print the guestDrinkPairs list
💡 Why This Matters
🌍 Real World
Combining two related lists is common when you want to pair data, like matching names with preferences or products with prices.
💼 Career
Understanding how to combine collections efficiently is useful in data processing, UI development, and backend programming.
Progress0 / 4 steps
1
Create the guests list
Create a list called guests with these exact names: "Alice", "Bob", "Charlie"
Kotlin
Need a hint?

Use listOf to create a list with the exact names.

2
Create the drinks list
Create a list called drinks with these exact drinks: "Coffee", "Tea", "Juice"
Kotlin
Need a hint?

Use listOf again to create the drinks list.

3
Combine guests and drinks with zip
Create a variable called guestDrinkPairs that uses zip to combine the guests and drinks lists
Kotlin
Need a hint?

Use guests.zip(drinks) to combine the two lists.

4
Print the guest and drink pairs
Print the guestDrinkPairs list to show the pairs of guests and their favorite drinks
Kotlin
Need a hint?

Use println(guestDrinkPairs) to display the pairs.