Perfect Ten-Minute Walk

Imagine walking around the block, where each step takes one minute and moves you north, south, east, or west. Write is_valid_walk, which checks the list of directions walk. Return True only if the walk lasts exactly 10 minutes and ends at the same point where it started.

Примеры

Ввод
["n", "s", "n", "s", "n", "s", "n", "s", "n", "s"]
Вывод
True
Ввод
["w", "e", "w", "e", "w", "e", "w", "e", "w", "e"]
Вывод
True
Ввод
["w"]
Вывод
False

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

def is_valid_walk(walk: list[str]) -> bool:

Теги

arraymath
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
["n","s","n","s","n","s","n","s","n","s"]
ExpectedTrue
2
Input
["w","e","w","e","w","e","w","e","w","e"]
ExpectedTrue
3
Input
["w"]
ExpectedFalse
4
Input
["n","n","n","s","n","s","n","s","n","s"]
ExpectedFalse
5
Input
["n","s","e","w","n","s","e","w","n","s"]
ExpectedTrue
6
Input
["w","e","w","e","w","e","w","e","w","e","w"]
ExpectedFalse
Focus radio
Paused · SomaFM · Fluid