Загрузка...

🧠 Python Quiz: Python map, filter, and reduce explained | Can You Get It Right?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🧠 QUIZ: PYTHON MAP, FILTER, AND REDUCE EXPLAINED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📚 Based on our last concept post:
Python map, filter, and reduce explained

✏️ Drop your answer (A / B / C / D) in the comments BEFORE scrolling!

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
❓ QUESTION
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Consider the following Python code snippet:

```python
numbers = [1, 2, 3, 4, 5]

# Operation 1: Apply a function to each element
mapped_numbers = map(lambda x: x * 2, numbers)

# Operation 2: Filter elements based on a condition
filtered_numbers = filter(lambda x: x 5, mapped_numbers)

# Operation 3: Reduce the filtered elements to a single value
final_result = reduce(lambda x, y: x + y, filtered_numbers)

print(final_result)
```

What will be the final output of this code?

A) 15 (1+2+3+4+5)
B) 30 (6+8+10)
C) 24 (6+8+10, sum of numbers 5 after doubling)
D) 10 (only 10 is 5 after doubling)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ ANSWER
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Correct answer: B

💡 EXPLANATION
The `map` function doubles each number in the `numbers` list, resulting in `[2, 4, 6, 8, 10]`. The `filter` function then selects numbers greater than 5 from this mapped list, resulting in `[6, 8, 10]`. Finally, the `reduce` function sums these filtered numbers (6 + 8 + 10), producing the output `24`.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
👍 LIKE the video if you got it right!
⬅ Missed the concept? Watch our previous video first!
🔔 SUBSCRIBE for daily Python quizzes and tutorials!
📤 SHARE this quiz with a coding friend!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

#Python #PythonMapFilter #Quiz #CodingQuiz #ProgrammingQuiz #CodingChallenge #LearnToCode #Programming #Developer #Tech #Education #DailyCoding

Видео 🧠 Python Quiz: Python map, filter, and reduce explained | Can You Get It Right? канала wong's learning
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять