Lesson 19 of 34
Dictionaries: নাম থেকে Value
10 min 30 XP
Dictionary আসল অভিধানের মতো কাজ করে: প্রতিটি key-র একটি value থাকে। { }-এর ভেতরে key: value জোড়া লিখুন। Values index দিয়ে নয়, key দিয়ে খোঁজা হয়।
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.না থাকা key চাইলে error হয়। get() তার বদলে None বা আপনার দেওয়া default ফেরত দেয়।
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.Keys আর values একসঙ্গে loop করতে items() ব্যবহার করুন।
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.গোনার জন্য dictionaries একদম উপযুক্ত: count[ch] = count.get(ch, 0) + 1। Interview-এ এটা বারবার আসে!