First Mirror Word

A palindrome reads the same from left to right and from right to left, like a small mirror word. Write a function first_palindrome that scans the list words in order. Return the first string that is a palindrome. If no palindrome exists, return an empty string.

Примеры

Ввод
["abc", "car", "ada", "racecar", "cool"]
Вывод
"ada"
Ввод
["notapalindrome", "racecar"]
Вывод
"racecar"
Ввод
["def", "ghi"]
Вывод
""

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

def first_palindrome(words: list[str]) -> str:

Теги

stringsarraytwo-pointers
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
["abc","car","ada","racecar","cool"]
Expected"ada"
2
Input
["notapalindrome","racecar"]
Expected"racecar"
3
Input
["def","ghi"]
Expected""
4
Input
["a"]
Expected"a"
5
Input
["ab","ba","aa"]
Expected"aa"
6
Input
[]
Expected""
Focus radio
Paused · SomaFM · Fluid