Chapter 5: Lists (Solutions to Even-Numbered Exercises)

Question 2

>>> alkaline_earth_metals = [4, 12, 20, 38, 56, 88]
>>> alkaline_earth_metals[4]
56
>>> alkaline_earth_metals[-2]
56

Question 4

>>> alkaline_earth_metals = [4, 12, 20, 38, 56, 88]
>>> max(alkaline_earth_metals)
88

Question 6

half_lives = [87.74, 24110.0, 6537.0, 14.4, 376000.0] 
for value in half_lives:
    print value

Question 8

country_populations = [1295, 23, 7, 3, 47, 21]
total = 0
for pop in country_populations:
    total = total + pop

Question 10

>>> temps = [25.2, 16.8, 31.4, 23.9, 28, 22.5, 19.6]
>>> temps.sort()
>>> temps
[16.800000000000001, 19.600000000000001, 22.5, 23.899999999999999, 25.199999999999999, 28, 31.399999999999999]

Question 12

temps_in_celsius = cool_temps + warm_temps

Question 14

>>> alkaline_earth_metals = [[4, 9.012], [12, 24.305], [20, 40.078], [38, 87.62], [56, 137.327], [88, 226]]

Question 16

number_and_weight = []
for metal in alkaline_earth_metals:
    number_and_weight.append(metal[0])
    number_and_weight.append(metal[1])

Question 18

Need drawing here.

Question 20

Mutable strings would be useful because we often want to transform them: rearrange characters, make uppercase, and so on. They are immutable because experience shows it makes programs faster. It also means that strings can be used in structures like dictionaries, which we will see in Chapter 9.