-
Notifications
You must be signed in to change notification settings - Fork 57
/
satisfiesF.py
29 lines (24 loc) · 830 Bytes
/
satisfiesF.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
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.
:param L:
:return: Returns the length of L after mutation
'''
falseCounter = 0;
falseFlag = 0;
falsePositions = [];
for i in range(0, len(L)):
if f(L[i]) == False:
falseCounter += 1;
falseFlag = 1;
falsePositions.append(i);
falsePositions.reverse();
if falseFlag == 1:
for i in range(0, falseCounter):
L.__delitem__(falsePositions[i]);
return len(L);
run_satisfiesF(L, satisfiesF)