-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quiz_Problem08.py
37 lines (28 loc) · 906 Bytes
/
Quiz_Problem08.py
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
# Quiz, Problem 8 - Summer 2016
# Testing..
def f(s):
return 'a' in s
def satisfiesF(L):
"""
Assumes L is a list of strings
Assume function f is already defined for you and it maps a string to a Boolean
Mutates L such that it contains all of the strings, s, originally in L such
that f(s) returns True, and no other elements. Remaining elements in L
should be in the same order.
Returns the length of L after mutation
"""
for x in reversed(L): # Reverse L, otherwise it skips indexes when it deletes!
if f(x) == True:
x #mute value..
else:
L.remove(x) # Remove from the list if f function is False.
return len(L)
#run_satisfiesF(L, satisfiesF) # Call in test.
# Testing
#L = ['a', 'b', 'a']
# Should print..
# 2
# ['a', 'a']
L = ['z', 'b', 'a', 'a', 'a', 'l', 'm']
print satisfiesF(L)
print L