Loading topic
dict) maps keys to values. You look up a value by its key instead of by a position, as you would with a list. This chapter covers the ways to build a dictionary, what the constructors do with duplicate keys, and the edge cases that catch people out. Later chapters cover hashable keys6 min read__init__ and __eq__. The goal is to learn exactly which objects Python accepts as dictionary keys, 6 min readstr, int, list, tuple), for loops and conditionals, and the difference between mutable and immutable objects. It also assumes you can create a dictionary and know that keys must be hashable, as covered in the earli6 min read[], get() and in. You should also know the difference between mutable and immutable objects, because dictionaries are mutable and that has consequences. After this chapter you will be able to change a dictionary in place, c4 min readfor loops and f-strings and that you know how to create, read and change a dictionary. It also assumes you know that tuples unpack into several names. Here you will learn what a dictionary produces when you loop over it, what the three view objects are, and how t5 min readkeys(), values() and items(). It also assumes you know the difference between mutable and immutable objects. Here you will learn what order a dictionary keeps, what that order does and does not a5 min readitems(), hashable keys, and insertion order. It also assumes you can read a list comprehension and know how for loops a5 min read[] and get(), and update entries by assignment. You should also know what a for loop and a list are. The chapter covers the two most common jobs for a dictionary: counting things and grouping things. It shows the manual pattern f6 min readitems() yields key-value pairs, and have used lambda and sorted() on lists. Insertion order, which the earlier chapter covers, matters here because it is the only "order" a dictionary has.5 min readget(), del, pop(), items(), and comprehensions. You should also know that for loops pull one item at a time from an iterator. The chapter covers why a loop that changes its own dictionary fails, which changes are sa5 min readd[key] takes about the same time in a dictionary of ten entries as in one of ten million. It assumes you know how to create, read and change dictionaries, what hashable means, and the difference between mutable and immutable objects. It also assumes you are comfortable re6 min read