Lesson 19 of 34
Dictionaries: பெயர் → மதிப்பு
10 min 30 XP
dictionary என்பது ஒரு அகராதி போல: ஒவ்வொரு key-க்கும் ஒரு value. { } அடைப்புக்குறியில் key: value என்று எழுதுங்கள். Index-க்கு பதிலாக key-ஐப் பயன்படுத்தி மதிப்பைப் பெறலாம்.
Example: edit me and press Run
Press Run to see the result here.இல்லாத key-ஐக் கேட்டால் error வரும். get() பயன்படுத்தினால் error இல்லாமல் None அல்லது நாம் சொல்லும் மதிப்பு கிடைக்கும்.
Example: edit me and press Run
Press Run to see the result here.items() மூலம் key மற்றும் value இரண்டையும் loop-ல் பெறலாம்.
Example: edit me and press Run
Press Run to see the result here.எழுத்துகளை எண்ண dictionary மிகச் சிறந்தது: count[ch] = count.get(ch, 0) + 1. இது interview-களில் அடிக்கடி வரும்!