❶ 如何python编程输入若干个中间以空格隔开的整数,并从大到小进行排序,并将结果输出(每行输出1个数)
temp = '2 3 11'
temp = temp.split(' ')
temp = [int(v) for v in temp]
temp.sort(reverse=True)
❷ python中怎么让前5个升序,后五个降序,派Python中输入十个数字,怎么让前五个升序
分成两个列表分别排序,代码如下:
s = input().split()
l1 = [ int(x) for x in s[:5] ] # 前5个数字
l2 = [ int(x) for x in s[-5:] ] # 后5个数字
l1.sort() # 前5个数字升序
l2.sort(reverse=True) # 后5个数字降序
print(l1 + l2)
运行结果如下:
输出符合题意,望采纳~
❸ python中编写一个模块,模块中包含随机生成N个元素的列表、排序列表、求最大
下面是一个 Python 模块的例子,它包含了随机生成 N 个元素的列表、排序列表、求最大值三个功能:
这样,就可以使用 my_mole 模块中的函数来生成随机列表、排序列表、求出最大值。
❹ 【问题描述】 输入n的值和n个数,进行排序并输出。 【输入形式】 首先输入整数个数n; 接着输入n
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a.sort()
print(a)
❺ 如何用Python列出N个数字的所有排列组合
>> from itertools import combinations, permutations
>> permutations([1, 2, 3], 2)
<itertools.permutations at 0x7febfd880fc0>
# 可迭代对象
>> list(permutations([1, 2, 3], 2)) #排列
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
>> list(combinations([1, 2, 3], 2)) #组合
[(1, 2), (1, 3), (2, 3)]