字典处理"/>
【python】字典处理
已知字符串s="When in the course of human events,it becomes necessary for one people to dissolve the political bands which have connected them with another,and to assume among the Powers of the earth,the separate and equal station to which the Laws of Nature and of Nature's God entitle them,a decent respect to the opinions of mankind requires that they should declare the causes.",编写程序,实现如下功能。
- 输出按不重复单词(不区分大小写)的长度的降序排列的列表。
- 生成一个新字典,字典的关键字是单词长度,字典的值是长度相同的单词放在一起组成的列表。输出新字典。
s=s.lower().replace(","," ").replace("."," ")
lst1=list(set(s.split()))
#print(lst1)
print("按不重复单词长度降序排列的列表为:")
更多推荐
【python】字典处理
发布评论