Use a single-line list comprehension to create the following list:
- A list of all the odd numbers from 17 to 34.
- A list of all the odd numbers in:
years = [1492, 1776, 1812, 1945, 1969, 1984, 1985, 2001, 2015]
- The square of all numbers from 4 to 14.
- The number of times each digit occurs in the sequence:
pi = "141592653589793238462643383279502881"
. (Hint: str.count('0'). Hint: your answer should be a list 10 items long, one for each digit 0 through 9.)
Use a single-line dictionary comprehension to create a dictionary of the following terms.
- Using
zip
, where the keys arekeys = ["a", "b", "c"]
and the values arevalues = [1, 2, 3]
. - A dictionary where the keys are 1 through 10 and the values are the cube of the keys.
- A dictionary where the keys are 1 through 10 and the values are True if the key is odd and False if even.