나는 이렇게 학습한다/Algorithm & SQL

1006. Filter out the geese

daco2020 2022. 10. 6. 22:48
반응형

Write a function that takes a list of strings as an argument and returns a filtered list containing the same elements but with the 'geese' removed.

The geese are any strings in the following array, which is pre-populated in your solution:

  ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]

For example, if this array were passed as an argument:

 ["Mallard", "Hook Bill", "African", "Crested", "Pilgrim", "Toulouse", "Blue Swedish"]

Your function would return the following array:

["Mallard", "Hook Bill", "Crested", "Blue Swedish"]

The elements in the returned array should be in the same order as in the initial array passed to your function, albeit with the 'geese' removed. Note that all of the strings will be in the same case as those provided, and some elements may be repeated.



Solution:

geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]

def goose_filter(birds):
    return [bird for bird in birds if bird not in geese]


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

1008. Drink about  (0) 2022.10.08
1007. Volume of a Cuboid  (0) 2022.10.08
1005. Palindrome Strings  (0) 2022.10.05
1004. Keep up the hoop  (0) 2022.10.04
1003. Find the Remainder  (0) 2022.10.03