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() 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. ఇది ఇంటర్వ్యూలలో తరచుగా వస్తుంది!

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.