Python练习题答案: 鼓舞人心的弦乐【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

鼓舞人心的弦乐【难度:1级】:

答案1:

def longest_word(string_of_words):
    return max(reversed(string_of_words.split()), key=len)

答案2:

def longest_word(string_of_words):
    # Give me back the longest word!
    return max(reversed(string_of_words.split(' ')),key = len)

答案3:

def longest_word(string_of_words):
    # Give me back the longest word!
    return max(reversed(string_of_words.split()),key=len)

答案4:

def longest_word(string_of_words):
    return max(reversed(string_of_words.split(' ')), key=len)

答案5:

def longest_word(s):
    return sorted(s.split(), key = len)[-1]

答案6:

def longest_word(s):
    return sorted(s.split(' '), key=len)[-1]

答案7:

def longest_word(words):
    return max(reversed(words.split()), key=len)

答案8:

def longest_word(words):
    return max(reversed(words.split(' ')), key=len)

答案9:

def longest_word(string_of_words):
    words = string_of_words.split()[::-1]
    return max(words, key = len)

答案10:

def longest_word(string_of_words):
    # Give me back the longest word!
    pass
    words = string_of_words.split()[::-1]
    return max(words, key = len)

答案11:

longest_word = lambda s: max(s.split()[::-1],key=len)

答案12:

longest_word = lambda s: max(s.split(' ')[::-1], key = len)

答案13:

def longest_word(string_of_words):
    return ''.join(sorted(string_of_words.split(' '), key=len)[-1])

答案14:

def longest_word(str_):
     return max(str_.split(' '), key=lambda x: (len(x), str_.index(x)))

答案15:

from collections import defaultdict


def group_by(f, xs):
    groups = defaultdict(list)
    for x in xs:
        groups[f(x)].append(x)
    return groups


def last(xs):
    return xs[-1]


def longest_word(string_of_words):
    # Give me back the longest word!
    words_by_len = group_by(len, string_of_words.split(' '))
    return last(words_by_len[max(words_by_len.keys())])

答案16:

def longest_word(text):
    m = 0
    s = ""
    for x in text.split(" "):
        if(len(x) >= m):
            m = len(x)
            s = x
    return s​

答案17:

def longest_word(string_of_words):
    return sorted(string_of_words.split(), key=len)[-1]

答案18:

def longest_word(string_of_words):
    return sorted(string_of_words.split(' '),key=len)[-1]

答案19:

def longest_word(string_of_words):
    return sorted(string_of_words.split(" "), key=len)[-1]



Python基础训练营景越Python基础训练营QQ群

在这里插入图片描述
欢迎各位同学加群讨论,一起学习,共同成长!

你可能感兴趣的:(Python编程初级练习题)