Four-Letter Friends
Imagine filtering a guest list where only names with exactly 4 characters count as friends. Write friend, which takes a list names and keeps only those names. The matching names should stay in the same order as they appeared in the input list.
Примеры
Ввод
["Ryan", "Kieran", "Mark"]Вывод
["Ryan", "Mark"]Ввод
["Ryan", "Jimmy", "123", "4", "Cool Man"]Вывод
["Ryan"]Ввод
["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooool"]Вывод
["Jimm", "Cari", "aret"]Нужно реализовать
def friend(names: list[str]) -> list[str]:
Теги
arraystrings
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesVisible tests
1
Input
["Ryan","Kieran","Mark"]Expected
["Ryan","Mark"]2
Input
["Ryan","Jimmy","123","4","Cool Man"]Expected
["Ryan"]3
Input
["Jimm","Cari","aret","truehdnviegkwgvke","sixtyiscooool"]Expected
["Jimm","Cari","aret"]4
Input
[]Expected
[]5
Input
["Love","Your","Face","1"]Expected
["Love","Your","Face"]6
Input
["Ryan"]Expected
["Ryan"]Focus radio
Paused · SomaFM · Fluid