Prefix Matches

A prefix is the beginning of a word, such as "pre" in "prefix". This kind of check is common in search and autocomplete when a user has typed the first few letters. Write a function count_prefixes that receives a list of words and a string pref. Return how many words start with that prefix.

Примеры

Ввод
["pay", "attention", "practice", "attend"], "at"
Вывод
2
Ввод
["leetcode", "win", "loops", "success"], "code"
Вывод
0
Ввод
["abc", "abcd", "ab"], "abc"
Вывод
2

Нужно реализовать

def count_prefixes(words: list[str], pref: str) -> int:

Теги

stringsarray
PostgreSQLv16

Hawn jidher ir-riżultat tat-tħaddim tal-kodiċi

Visible tests
1
Input
["pay","attention","practice","attend"], "at"
Expected2
2
Input
["leetcode","win","loops","success"], "code"
Expected0
3
Input
["abc","abcd","ab"], "abc"
Expected2
4
Input
[], "x"
Expected0
5
Input
["go","good","gone"], "go"
Expected3
6
Input
["a","b","c"], ""
Expected3
Focus radio
Paused · SomaFM · Fluid