Words With Character
This search works like a simple filter: find every word that contains a chosen letter or symbol. Write a function words_containing that receives a list of words and a character x. Return the indices of words that contain this character, in ascending order. If no words match, return an empty list.
Примеры
Ввод
["leet", "code"], "e"Вывод
[0, 1]Ввод
["abc", "bcd", "aaaa", "cbc"], "a"Вывод
[0, 2]Ввод
["abc", "bcd", "aaaa", "cbc"], "z"Вывод
[]Нужно реализовать
def words_containing(words: list[str], x: str) -> list[int]:
Теги
stringsarray
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inVisible tests
1
Input
["leet","code"], "e"Expected
[0,1]2
Input
["abc","bcd","aaaa","cbc"], "a"Expected
[0,2]3
Input
["abc","bcd","aaaa","cbc"], "z"Expected
[]4
Input
["x"], "x"Expected
[0]5
Input
["a","b","c"], "b"Expected
[1]6
Input
[], "a"Expected
[]Focus radio
Paused · SomaFM · Fluid