1.2.33 · D1 · HinglishIntroduction to Programming (Python)

FoundationsBuilt-in functions — map, filter, zip, enumerate, sorted, reversed, min, max, sum, any, all

2,051 words9 min read↑ Read in English

1.2.33 · D1 · Coding › Introduction to Programming (Python) › Built-in functions — map, filter, zip, enumerate, sorted, re

Isse pehle ki tum sorted(words, key=len, reverse=True) par trust kar sako, tumhe jaanna hoga ki list kya hai, lambda kya hai, key= ka kya matlab hai, % kya compute karta hai, aur kyun map(...) <map object> print karta hai. Yeh page har ek cheez ko scratch se banata hai, us order mein jisme wo ek doosre par depend karti hain.


0. Sabse basic picture: ek box jo cheezein ek row mein rakhta hai

Yahaan sab kuch ek collection of items jo order mein baithe hain se shuru hota hai. Python mein everyday version hai list, jo square brackets aur commas ke saath likhi jaati hai.

Figure — Built-in functions — map, filter, zip, enumerate, sorted, reversed, min, max, sum, any, all

Yahaan se kyun shuru karein? Parent page ka har ek function (map, filter, sorted, …) iss tarah ka ek box leta hai aur uske saath kuch karta hai. Agar box aur uska index counting crystal clear nahi hai, toh kuch bhi samajh nahi aayega.


1. Iterable — koi bhi cheez jise tum ek waqt mein ek item ke through walk kar sako

List ek badi idea ka ek example hai.

Topic ko yeh word kyun chahiye: docs kehte hain map(f, iterable), map(f, list) nahi, kyunki ye functions kisi bhi walkable cheez par kaam karte hain — ek string, ek file, ek range — sirf lists par nahi.


2. Function aur lambda — ek rule jo tum doosri machine ko de sakte ho

Kabhi kabhi tumhe itna chota rule chahiye hota hai ki usse naam dena zaroori nahi. Isliye lambda hai.

Figure — Built-in functions — map, filter, zip, enumerate, sorted, reversed, min, max, sum, any, all

Topic ko iska kyun zaroorat hai: map, filter, sorted, min, max sab chahte hain ki tum ek rule as an argument pass karo. lambda tumhe woh rule inline likhne deta hai instead of pehle poora named function define karne ke. Deep dive: Lambda functions.


3. **, %, <, == symbols jo examples mein use hote hain

Parent page kaafi operators silently use karta hai. Yeh raha, zero se.

Topic ko inki kyun zaroorat hai: filter(lambda x: x % 2 == 0, xs) even numbers ko isliye rakhta hai kyunki x % 2 == 0 woh test hai "kya 2 se divide karne par kuch nahi bachta?"


4. Truthy / falsy — ek value kaise yes-or-no count hoti hai

filter, any, aur all ko strict True/False ki zaroorat nahi hoti; ye kuch bhi accept karte hain aur poochhte hain "kya yeh yes count hota hai?"

Topic ko iska kyun zaroorat hai: filter(None, xs) "saari falsy items drop karta hai," aur any/all truthiness ke baare mein pooch rahe hain, literal True ke baare mein nahi. Deep dive: Truthiness in Python.


5. Laziness — woh machine jo tab tak wait karti hai jab tak poochha na jaaye

Yeh parent page par sabse confusing behaviour hai, isliye hum isse carefully banate hain.

Figure — Built-in functions — map, filter, zip, enumerate, sorted, reversed, min, max, sum, any, all

Topic ko iska kyun zaroorat hai: map, filter, zip, enumerate, reversed sab lazy iterators return karte hain. Isliye print(map(...)) numbers ki jagah <map object> dikhata hai — tumne kabhi results ke liye poochha hi nahi. Deeper: Iterators and generators.


6. * spread aur tuple unpacking

Parent page ke "unzip" trick mein notation ke do aakhri pieces.

Topic ko iska kyun zaroorat hai: elegant zip(*pairs) "unzip" sirf isliye kaam karta hai kyunki * pairs ki ek list ko kai alag pairs mein badal deta hai jo zip ko di jaati hain.


7. key= — kisi derived value se sort/compare karo

Topic ko iska kyun zaroorat hai: key ke bina, sorting poore items ko directly compare karti hai; key tumhe bolne deta hai "sirf is aspect se compare karo." Yeh §2 (functions) aur §0 (indexing) ki sab cheezein reuse karta hai.


Ye foundations topic ko kaise feed karte hain

List and index from 0

Iterable walk one at a time

Lazy iterator single use

Function as a rule

lambda inline rule

key argument

Operators percent power equals

Predicate true or false

Truthy and falsy

The 11 built in functions

Star spread and unpacking

Left side par sab prerequisites hain; ye sab parent topic ke gyarah functions mein flow karte hain. Wahaan se natural next steps hain List comprehensions (map+filter ka compact alternative), functools.reduce (sum/min/max ka general form), aur Sorting algorithms (jo sorted under the hood karta hai).


Equipment checklist

[10, 20, 30] mein, 20 kis index par hai?
Index 1 — Python 0 se count karta hai.
iterable ka kya matlab hai?
Koi bhi cheez jise tum ek waqt mein ek item through walk kar sako (list, tuple, string, range).
lambda x: x + 1 ko plain words mein padho.
"x diya, x plus one return karo" — ek tiny nameless function.
7 % 2 evaluate hokar kya deta hai aur kyun?
1 — 7 ko 2 se divide karne ke baad remainder.
= aur == mein kya fark hai?
= ek value store karta hai; == check karta hai ki do values equal hain ya nahi.
Teen falsy values ke naam batao.
0, '' (empty string), [] / None / False (inme se koi bhi).
print(map(str, [1,2,3])) <map object> kyun dikhata hai?
map lazy hai — tumne kabhi results ke liye nahi poochha; list(...) mein wrap karo.
Agar tum same map object par list() do baar call karo toh kya hoga?
Doosra call [] dega — ek lazy iterator single-use hota hai / pehli walk ke baad exhausted ho jaata hai.
zip(*pairs) mein *pairs kya karta hai?
List ko separate arguments mein spread karta hai, taaki har pair zip ko individually diya jaaye.
key=len sorted ko kya batata hai?
Har item ko item khud ki jagah uski length se judge/order karo.