- Write a function called
averageWord(s). It will have a single string parameter. It will return the average length of a word in s.
>>> averageWord('A sample sentence')
5.0
- Write a function called
prefixes(s, n) that puts together in a list all prefixes of s of length n:
>>> prefixes('This long tiring walk', 3)
['Thi', 'lon', 'tir', 'wal']
- Write a function called
product(nums) that computes the product of all of the numbers in the list nums:
>>> product([4, -2, 3, -5])
120
- Write a function called
positive(nums) that returns a list containing all of the numbers in the list nums that are positive:
>>> positive([4, -2, 0, 3, -5, 12])
[4, 3, 12]
- Write a function called
evens(nums) that returns a list containing all of the numbers in the list nums that are even:
>>> evens([4, -2, 0, 3, -5, 12])
[4, -2, 0, 12]
- Write a function called
posEven(nums) that returns a list containing all of the numbers in the list nums that are both positive and even. Your implementation should call both positive(nums) and evens(nums):
>>> posEven([4, -2, 0, 3, -5, 12])
[4, 12]