python 统计一句话中最长单词

1.写一个程序:输入一个句子,输出该句子中最长的单词.

2.数据文件data.txt(在ftp://public.sjtu.edu.cn上)的每一行都有用逗号分隔的15个数据,意义如下(忽略x):
x,x,x,教育程度,x,x,x,x,种族,性别,x,x,x,x,收入

教育程度值:Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.
种族值: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.
性别值: Female, Male.
收入值:<=50K, >50K

请分类统计各种人群的收入情况,即某种人中<=50K和>50K的各占多少?
教育:有学位的人(Bachelors/Masters/Doctorate) vs 其他人
种族:白人(White)vs 其他人
性别:男人(Male)vs 女人(Female)

用图形给出直观的结果(例如用分为两色的柱状图表示各占的比例)。

第1个回答  推荐于2016-02-17
if __name__ == '__main__':
say_words = rawinput(“请输入要测试的一句话”)
word_list = say_words.split(',') //用逗号转换为列表
word_len_list = [len(word) for word in say_words]
max_word_len = max(word_len_list)
for word in say_words:
if len(word) == max_word_len:
print word, "是最长的单词之一"本回答被提问者和网友采纳
相似回答