Lesson 19 of 34

Dictionaries: பெயர் → மதிப்பு

10 min 30 XP

dictionary என்பது ஒரு அகராதி போல: ஒவ்வொரு key-க்கும் ஒரு value. { } அடைப்புக்குறியில் key: value என்று எழுதுங்கள். 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() பயன்படுத்தினால் error இல்லாமல் None அல்லது நாம் சொல்லும் மதிப்பு கிடைக்கும்.

Example: edit me and press Run

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

items() மூலம் key மற்றும் value இரண்டையும் loop-ல் பெறலாம்.

Example: edit me and press Run

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

எழுத்துகளை எண்ண dictionary மிகச் சிறந்தது: count[ch] = count.get(ch, 0) + 1. இது interview-களில் அடிக்கடி வரும்!

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.