fork download
  1. def countPrefix(words, prefix):
  2. return len([1 for w in words if w.startswith(prefix)])
  3.  
  4. words = ['rato', 'roeu', 'rolha', 'rainha', 'rei', 'russia']
  5. pref = ['ro', 'ra', 'r']
  6.  
  7. result = [countPrefix(words, p) for p in pref]
  8.  
  9. print result
Success #stdin #stdout 0s 7692KB
stdin
Standard input is empty
stdout
[2, 2, 6]