Using list comprehension, str.startswith
and sum
[sum(w.startswith(p) for w in word) for p in prefix] # [4, 2, 1]
3
solved Count number of occurrences in a list
Using list comprehension, str.startswith
and sum
[sum(w.startswith(p) for w in word) for p in prefix] # [4, 2, 1]
3
solved Count number of occurrences in a list