我如何正确实现[关闭]

问题描述 投票:0回答:2
我们将Starwars-rorder定义为数字列表上的操作,因此,如果订购了列表,第一个第三次移动到中心,则中锋第三次移动到前面,最后三分之一持续。

python sorting
2个回答
1
投票
numbers.sort()

现在可以将其划分为三分之一。让我们定义结果列表,然后我们可以在内部添加thits
result=[]
length=len(numbers) //3 # this will be used to divide thirds
result.extend(numbers[length:(length*2)] # adding mid third to first place
result.extend(numbers[:length]) # adding initial third to middle place
result.extend(numbers[(length*2):] # adding last third to last place
print(results)

问题陈述尚不清楚。目的是可能需要对输入值进行排序。但是,尝试测试输入是否已经分类并没有意义 - 只是对它们进行排序。
导致:

0
投票
if __name__ == "__main__": # calculate the width of each segment d = int(input()) // 3 # split the line into whitespace delimited tokens # convert the tokens to integers # sort the values and create a list values = sorted(map(int, input().split())) # print the three segments in Starwars order print(*values[d:d+d], *values[:d], *values[d+d:])

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.