Need Assistance?

support@tutorialshub.in

Collections and Strings

Tuples and sets

ADVERTISEMENT
Python Free Lesson
5 min read
ADVERTISEMENT

Dictionaries model key-value data

A dictionary is a mapping from keys to values. It is a natural representation for records, configuration and lookup tables. The important operation is retrieving a value by its key rather than by position.

Safe and explicit access

Use direct indexing when a missing key is an error, and get() when a default value is acceptable. Use items(), keys() and values() when iterating according to what the algorithm needs.

Nested application data

API responses often contain dictionaries nested inside lists and other dictionaries. Treat such data as external input: check that required fields exist and have the expected types before relying on them.

Practice: create a customer object with an address and orders, then calculate and display useful information from the nested structure.

ADVERTISEMENT