fork download
  1. def f(s):
  2. return 'a' in s
  3.  
  4. def satisfiesF(k):
  5. """
  6. Assumes L is a list of strings
  7. Assume function f is already defined for you and it maps a string to a Boolean
  8. Mutates L such that it contains all of the strings, s, originally in L such
  9. that f(s) returns True, and no other elements. Remaining elements in L
  10. should be in the same order.
  11. Returns the length of L after mutation
  12. """
  13. res = []
  14. for a in k:
  15. if f(a):
  16. res.append(a)
  17. global L
  18. L = res
  19. return len(res)
  20.  
  21. L = ['a', 'b', 'a']
  22. print(satisfiesF(L))
  23. print(L)
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
2
['a', 'a']