Lesson · Hinglish · ⏱ 7 min padhne mein
🧺 Lists aur dictionaries: bahut saari values store karna
EnglishHinglish
🏠 Asli zindagi ki misaal
Shopping list ordered hoti hai: pehle doodh, phir bread, phir ande. Yeh Python ki list hai. Phone ki contact book naam ko number se jodti hai: 'Amma → 98xxxx'. Aap position se nahi, naam se dhoondhte ho. Yeh dictionary hai.
💡 Aasaan shabdon mein
Real data groups mein aata hai, isliye Python mein collections hain. List [ ] items ko order mein rakhti hai, aur aap unhe position se access karte ho, jo 0 se shuru hoti hai. Dictionary { } key → value pairs store karti hai, aur aap key se value dhoondhte ho, jo bahut fast hota hai. Tuple ( ) list jaisa hai lekin badla nahi ja sakta, aur set sirf unique items rakhta hai. AI kaam mein aap jo data dekhoge, jaise APIs ka JSON, woh zyaadatar dictionaries ki list hota hai.
🪜 Step by step
- List: ordered collection jise badal sakte ho. scores = [72, 88, 95]; scores.append(60); scores[0] pehla item hai.
- Dictionary: key se cheezein dhoondo. emp = {"name": "Ravi", "city": "Pune"}; emp["city"] se "Pune" milta hai. Key missing ho sakti hai to emp.get("age", 0) use karo.
- Set: unique values, membership check bahut tez. seen = set(); if user_id in seen: ... Duplicates hataane ke liye badhiya.
- Inpe loop chalao: for k, v in emp.items(): print(k, v). Zyaadatar asli data dictionaries ki list hota hai, jaise API ki rows.
- Comprehensions se jaldi nayi lists banao: high = [s for s in scores if s > 80].
🔑 Zaroori shabd
- List
- Ordered collection: ['milk', 'bread'].
- Dictionary
- Key → value pairs: {'name': 'Asha', 'city': 'Pune'}.
- Index
- List mein item ki position. Pehla item index 0 pe hota hai.
👀 Example dekho
cart = ["milk", "bread", "eggs"]
print(cart[0]) # milk
cart.append("tea")
prices = {"milk": 30, "bread": 45, "eggs": 72, "tea": 120}
total = sum(prices[item] for item in cart)
print(total) # 267Cart ke items ke liye list, aur har item ka price dhoondhne ke liye dictionary.
⚠️ Aam galtiyaan jinse bachna hai
- Loop ke andar badi list mein 'in' se dhoondhna. Bahut slow hota hai; pehle set mein convert karo.
- Key na ho to emp["age"] se KeyError. .get() use karo ya 'if "age" in emp' check karo.
- Loop chalate hue list badalna. Iske bajaye nayi list banao.
✅ Jaldi se check karo
Aapko roll number se student ke marks dhoondhne hain. Sabse best kya hai?
- List
- Ek string
- Dictionary
Jawaab dekho
C. Dictionary: Dictionary key (roll number) ko seedha value (marks) se map karti hai, position mein dhoondhna nahi padta.
🙋 Seekhne wale yeh poochhte hain
List ya dictionary: kaise chunu?
Agar items position se access karte ho ya order mein chalte ho, to list. Agar naam ya ID se dhoondhte ho, to dictionary.
JSON kya hai aur iska kya rishta hai?
JSON woh text format hai jo APIs use karti hain. Yeh seedha Python dictionaries aur lists mein map hota hai: json.loads(text) se dicts aur lists milti hain, json.dumps(data) wapas text bana deta hai.
📌 Yaad rakho
List = items ki ordered line. Dictionary = naam (key) se dhoondho.
Poora course, aapke roadmap ke hisaab se
Progress tracking, quick checks aur step-by-step order ke saath. Yeh lesson in courses ka hissa hai:
AI Foundations Path · AI Product Engineer · LLM / Agent Engineer · AI Forward Deployed Engineer
Course mein seekho