물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Friend or Foe?

BEstyle 2022. 9. 28. 12:30

DESCRIPTION:

Make a program that filters a list of strings and returns a list with only your friends name in it.

If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours! Otherwise, you can be sure he's not...

Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"]

i.e.

friend ["Ryan", "Kieran", "Mark"] `shouldBe` ["Ryan", "Mark"]

Note: keep the original order of the names in the output.


def friend(x):
    return [name for name in x if len(name)==4]

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Find the odd int  (0) 2022.09.28
Ones and Zeros  (0) 2022.09.28
Reverse Letter  (0) 2022.09.28
Factorial  (0) 2022.09.27
Will you make it?  (0) 2022.09.27