Zip for combining sequences
📖 Scenario: Imagine you are organizing a small event and you 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 serving list.
🎯 Goal: Build a Swift program that uses zip to combine two arrays: one with guest names and one with their favorite drinks, then print each guest with their drink.
📋 What You'll Learn
Create an array called
guests with these exact names: "Alice", "Bob", "Charlie"Create an array called
drinks with these exact drinks: "Coffee", "Tea", "Juice"Use
zip to combine guests and drinksUse a
for loop with variables guest and drink to iterate over the zipped pairsPrint each guest and their favorite drink in the format:
"Alice likes Coffee"💡 Why This Matters
🌍 Real World
Combining related lists like names and preferences is common in event planning, data processing, and user interface development.
💼 Career
Understanding how to combine sequences efficiently is useful for software developers working with collections, data transformation, and UI data binding.
Progress0 / 4 steps