Lesson 19 of 34
Dictionaries: பெயர் → மதிப்புDictionaries: Names to Values
10 min 30 XP
dictionary என்பது ஒரு அகராதி போல: ஒவ்வொரு key-க்கும் ஒரு value. { } அடைப்புக்குறியில் key: value என்று எழுதுங்கள். Index-க்கு பதிலாக key-ஐப் பயன்படுத்தி மதிப்பைப் பெறலாம்.
A dictionary works like a real dictionary: every key has a value. Write key: value pairs inside { }. You look values up by key instead of by index.
Example: edit me and press Run
Press Run to see the result here.இல்லாத key-ஐக் கேட்டால் error வரும். get() பயன்படுத்தினால் error இல்லாமல் None அல்லது நாம் சொல்லும் மதிப்பு கிடைக்கும்.
Asking for a missing key gives an error. get() returns None, or a default you choose, instead.
Example: edit me and press Run
Press Run to see the result here.items() மூலம் key மற்றும் value இரண்டையும் loop-ல் பெறலாம்.
Use items() to loop over keys and values together.
Example: edit me and press Run
Press Run to see the result here.எழுத்துகளை எண்ண dictionary மிகச் சிறந்தது: count[ch] = count.get(ch, 0) + 1. இது interview-களில் அடிக்கடி வரும்!
Dictionaries are perfect for counting: count[ch] = count.get(ch, 0) + 1. This comes up in interviews all the time!