📘 Lesson · Lesson 81
Map, Filter, Reduce
Functional Tools
💡 एक नज़र में
map, filter और reduce पूरी list पर function लगाते हैं बिना loops लिखे — अक्सर lambda के साथ।
map() — हर एक transform
Python
nums = [1, 2, 3, 4] squared = list(map(lambda x: x*x, nums)) print(squared)
[1, 4, 9, 16]
filter() — कुछ रखें
Python
nums = [1, 2, 3, 4, 5, 6] even = list(filter(lambda x: x % 2 == 0, nums)) print(even)
[2, 4, 6]
reduce() — एक में मिलाएं
Python
from functools import reduce nums = [1, 2, 3, 4] total = reduce(lambda a, b: a + b, nums) print(total)
10
सारांश
- map हर item transform, filter matching रखता, reduce एक value में मिलाता।
- छोटे functions के लिए अक्सर lambda के साथ।
💻 लाइव कोड एडिटर
इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.