我是靠谱客的博主 感动盼望,这篇文章主要介绍python对列表单词排序_如何按长度对单词列表排序,现在分享给大家,希望可以做个参考。

我想根据长度对列表中的单词进行排序。

测试用例是{'cat','jump','blue','balloon'}

当运行此方法时,它将沿以下行打印一些内容:{'balloon','jump','blue','balloon'}

我遇到的另一个问题是,我们使用的python类型运行得很好,但是当我尝试在python 3.5.2shell中运行.py时,它会出现错误。

我只需要知道我做错了什么,我能做什么来修复它,让它工作。感谢您的帮助!

可以找到.py文件here:def wordSort():

words = []

minimum = 'NaN'

index = 0

x = 0

y = 0

z = 1

#How many words to be entered

length = input('How many words would you like to enter? ')

#Put words in the number of times you entered previously

while not z >= length + 1:

words.append(raw_input('Enter word #' + str(z) + ': '))

z += 1

while x < length:

minimum = words[x]

#Goes through the list and finds a smaller word

while y < length:

if len(words[y]) < len(minimum):

minimum = words[y]

index = y

y += 1

words[index] = words[x]

words[x] = minimum

x += 1

print words

最后

以上就是感动盼望最近收集整理的关于python对列表单词排序_如何按长度对单词列表排序的全部内容,更多相关python对列表单词排序_如何按长度对单词列表排序内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部