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.