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.