【每日一题20220322】筛选单词

:mage:‍给定一段纯英文长文本msg和一个数字n,请找出文本中长度比n大的单词组成的列表。

示例:
输入:“The quick brown fox jumps over the lazy dog”, 4
输出: ['quick', 'brown', 'jumps']

题目难度:简单
题目来源:CodeWars:Filter Long Words

def solution(msg: str, n: int) -> list:
    # your code here

assert solution("The quick brown fox jumps over the lazy dog", 4) == ['quick', 'brown', 'jumps']
assert solution("We have all got both light and darkness inside us",  6) == ['darkness']
assert solution("Hogwarts should win",  2) == ['Hogwarts', 'should', 'win']
def solution(msg: str, n: int) -> list:
    return [x for x in msg.split(' ') if len(x) > n]


assert solution("The quick brown fox jumps over the lazy dog", 4) == ['quick', 'brown', 'jumps']
assert solution("We have all got both light and darkness inside us", 6) == ['darkness']
assert solution("Hogwarts should win", 2) == ['Hogwarts', 'should', 'win']

优秀,越来越棒了!

def solution(msg: str, n: int) -> list:
    # your code here
    return [i for i in msg.split(" ") if len(i) > n]


assert solution("The quick brown fox jumps over the lazy dog", 4) == ['quick', 'brown', 'jumps']
assert solution("We have all got both light and darkness inside us",  6) == ['darkness']
assert solution("Hogwarts should win",  2) == ['Hogwarts', 'should', 'win']
def solution(msg: str, n: int) -> list:
    # your code here
    return [i for i in msg.split(' ') if len(i) > n]


assert solution("The quick brown fox jumps over the lazy dog", 4) == ['quick', 'brown', 'jumps']
assert solution("We have all got both light and darkness inside us", 6) == ['darkness']
assert solution("Hogwarts should win", 2) == ['Hogwarts', 'should', 'win']

def solution(msg: str, n: int) -> list:
    list_1=msg.split()
    return [i for i in list_1 if len(i)>n]
    def solution(msg: str, n: int) -> list:
        return [i for i in msg.split(' ') if len(i) > n]
def solution(msg: str, n: int) -> list:
   return [k for k in msg.split(' ') if len(k)>n]
def solution(msg: str, n: int) -> list:
    return [x for x in msg.split(' ') if len(x) > n]
def filter_long_words(sentence, n):
    return [x for x in sentence.split(' ') if len(x) > n]
def solution(msg: str, n: int) -> list:
    return [i for i in msg.split(' ') if len(i) > n]


assert solution("The quick brown fox jumps over the lazy dog", 4) == ['quick', 'brown', 'jumps']
assert solution("We have all got both light and darkness inside us", 6) == ['darkness']
assert solution("Hogwarts should win", 2) == ['Hogwarts', 'should', 'win']