-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathFixme.py
More file actions
86 lines (71 loc) · 1.73 KB
/
Fixme.py
File metadata and controls
86 lines (71 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python3
'''
Complete each function below so that the test cases pass.
Your solutions should use the map and filter functions,
and not for loops or list comprehensions.
'''
def evens(n):
'''
Returns a list of even numbers from 0 to n inclusive.
>>> evens(10)
[0, 2, 4, 6, 8, 10]
>>> evens(11)
[0, 2, 4, 6, 8, 10]
>>> evens(0)
[0]
>>> evens(1)
[0]
>>> evens(-1)
[]
'''
def threes(n):
'''
Returns a list of all numbers from 0 to n inclusive that contain the digit 3.
>>> threes(2)
[]
>>> threes(3)
[3]
>>> threes(10)
[3]
>>> threes(20)
[3, 13]
>>> threes(50)
[3, 13, 23, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43]
'''
def small_words(text):
'''
Returns a list of all words in the input text that are less than 5 characters long.
HINT:
Recall that text.split() converts the text variable into a list of words.
>>> small_words('this is a simple test case')
['this', 'is', 'a', 'test', 'case']
>>> small_words('really enormous words')
[]
>>> small_words('')
[]
>>> small_words('a big word is bad')
['a', 'big', 'word', 'is', 'bad']
'''
def squares(n):
'''
Returns a list of all square number between 1 and n inclusive.
Recall that the nth square number is defined to be n*n.
>>> squares(1)
[1]
>>> squares(2)
[1, 4]
>>> squares(3)
[1, 4, 9]
>>> squares(10)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
'''
def lengths(strings):
'''
Given a list of strings, returns a list of the lengths of the corresponding strings.
>>> lengths([])
[]
>>> lengths(['test'])
[4]
>>> lengths(['this','is','a','test'])
[4, 2, 1, 4]
'''