hw6.py.
def squares(nums): This function should return a list containing the square of each element from the input list nums.
>>> squares([1, 2, 3, 4]) [1, 4, 9, 16]
def smaller(nums, n): This function should return a list containing every element from nums that is less than n.
>>> smaller([10, 20, 30, 40], 25) [10, 20]
def multBy(nums, n): This function should return a list containing every element from nums multiplied by n.
>>> multBy([1, 2, 3, 4], 8) [8, 16, 24, 32]
def strings2points(strings): This function takes a list of strings. Each string contains two floating-point values separated by a space.
The function should return a list of tuples, each of which contains the two
corresponding float values.
>>> strings2points(["1.0 2.1", "3.2 4.5678", "6.4 1.9"]) [(1.0, 2.1), (3.2, 4.5678), (6.4, 1.9)]
def splitUp(points): This function takes a list of two-element tuples. The function should return two lists: The first list contains the first element of each tuple, and the second list contains the second element of each tuple.
>>> splitUp([(1.0, 2.1), (3.2, 4.5678), (6.4, 1.9)]) ([1.0, 3.2, 6.4], [2.1, 4.5678, 1.9])
def lowerCase(strings): This function takes a list of strings and returns a list of those same strings all converted to lower case.
>>> lowerCase(["Hello", "Goodbye", "SHOUT", "quiet"]) ['hello', 'goodbye', 'shout', 'quiet']
def stripped(strings): This function takes a list of strings and returns a list of those same strings purged of leading and trailing whitespace.
>>> stripped([" leading space", "trailing space ", " both types ", "neither type"]) ['leading space', 'trailing space', 'both types', 'neither type']
def onlyWith(strings, target): This function takes a list of
strings and returns a list of only those strings with target as
a substring.
>>> onlyWith(["hello", 'goodbye', 'good riddance', 'baby goo'], 'good') ['goodbye', 'good riddance']
def flatten(lst): Given a list of lists, it will return a list with the sublist elements as its elements:
>>> flatten([[1,2,3],[4,5],[6,7,8,9]])
[1, 2, 3, 4, 5, 6, 7, 8, 9]
dierolls().def dierolls(n):[0]*13 instead of [0]*12
to initialize your list.
>>> dierolls(50) [0, 0, 3, 2, 3, 2, 5, 6, 9, 8, 4, 6, 2] >>> dierolls(100) [0, 0, 5, 4, 8, 13, 13, 16, 8, 15, 9, 6, 3] >>> dierolls(200) [0, 0, 3, 13, 14, 37, 19, 32, 20, 23, 16, 17, 6]
stumble1()
to implement this program. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0] [0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0] [0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0] [0, 0, 0, 0, 0, 1, 2, 2, 0, 0, 0] [0, 0, 0, 0, 0, 1, 2, 2, 1, 0, 0] [0, 0, 0, 0, 0, 1, 2, 2, 1, 1, 0] [0, 0, 0, 0, 0, 1, 2, 2, 2, 1, 0] [0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 0] [0, 0, 0, 0, 0, 1, 2, 2, 3, 2, 0] [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 0] [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 1] [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 1]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0] [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0] [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0] [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]