Dictionaries, OOP & Classes
Prof. Dr. Nicolas Rohleder, Prof. Dr. Björn Eskofier, Veronika Ringgold, Luca Abel, Robert Richer · 7 concepts · 10 questions
Concept 1 / 7
Dictionaries: Creation, Access, and Iteration
A dictionary (dict) is an unordered collection of key–value pairs. Each key acts as a named property, and every key maps to exactly one value. Dictionaries are useful whenever you want to group related pieces of data under meaningful names rather than positional indices.
Creating a dictionary:
course_info = {
'name': 'Applied Data Science',
'university': 'FAU',
'term': 'summer term'
}Accessing a value by key:
print(course_info['university']) # → FAUIterating over all entries:
print(course_info.keys()) # dict_keys(['name', 'university', 'term'])
print(course_info.values()) # dict_values(['Applied Data Science', 'FAU', 'summer term'])
print(course_info.items()) # pairs of (key, value)The methods .keys(), .values(), and .items() return view objects — they reflect the current state of the dictionary at all times.