-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsatisfiesF.py
More file actions
29 lines (23 loc) · 774 Bytes
/
satisfiesF.py
File metadata and controls
29 lines (23 loc) · 774 Bytes
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
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
"""
# Your function implementation here
L_delete = []
for string in L:
if f(string)==False:
L_delete.append(string)
for string in L_delete:
L.remove(string)
return len(L)
run_satisfiesF(L, satisfiesF)
def f(s):
return 'a' in s
L = ['a', 'b', 'a']
print satisfiesF(L)
print L