Chapter 10
10.1 Dictionary basics
"Sunday", "Monday", "Tuesday" are key items.
"a"
and
"A"
are two different keys because
"a"
and
"A"
are different characters.
10.2 Dictionary creation
dict() function can create a dictionary object from a list of tuples. The first element of each tuple acts as the key, and the second element is the value.
10.3 Dictionary operations
get() function will be returned if the key is not found in the dictionary.
1
,
2
, and
3
. When printing numbers.values(), dict_values([1, 2, 3]) is printed.
"one", "two", "three". Using the list() constructor, a list object containing all keys is returned.
update() function modifies the value associated with the key
"Kabob"
and adds a new item, "Sushi": "$16".
10.4 Conditionals and looping in dictionaries
"orange"
, with associated value
5
, exists in the dictionary and the return value is
True
.
"apple"
,
"orange"
, and
"banana"
, and prints the keys space-separated.
10.5 Nested dictionaries and dictionary comprehension
numbers, and associated values are the powers of two.
names list, and associated values are the length of each string.