Lesson 19 of 34

Dictionaries: नावांपासून Values

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. हे interviews मध्ये सतत येते!

Challenge

+30 XP

input() ने एक शब्द वाचा. Dictionary वापरून प्रत्येक अक्षर किती वेळा आले ते मोजा, मग dictionary print करा. उदाहरण: "hello" → {'h': 1, 'e': 1, 'l': 2, 'o': 1}

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.