【发布时间】:2019-05-04 12:25:33
【问题描述】:
目前我的代码适用于列表,但不适用于句子。我需要帮助将句子变成列表。我应该在哪里将 .split 函数输入到我的代码中?
def stats(word_list):
'prints number, longest and average length of word_list'
length = len(word_list)
print("The number of words is {}.".format(length))
char_count = 0
longest_so_far = ""
for word in word_list:
# char_count = char_count + len(word)
char_count += len(word)
if len(word) > len(longest_so_far):
longest_so_far = word
print("The longest word is " + longest_so_far + ".")
average = char_count / length
message = "The average length is {}.".format(average)
print(message)
【问题讨论】:
-
考虑接受对你有用的答案。
-
如果我的回答对你有用!请考虑接受它@riser1234 :)
标签: python function split python-3.7