朋友们这到底应该怎么写我被困住了,这个Python怎么写才能通过啊
a = input()
lst = sorted(a.split(' '), key = lambda x: int(x),reverse=True)
print(' '.join(lst))
我的思路如下:
1、使用input获取一行数字输入,然后用split()按空格分割成列表;
2、将输入的字符串数字列表转为数字列表;
3、然后使用列表的sort()函数将列表从大到小排序;
4、最后使用for循环遍历列表,打印结果即可。
代码如下:
参考链接:
https://www.jb51.net/article/261970.htm
Python列表中字符串转数字的方法_Python热爱者的博客-CSDN博客_python字符串列表转换成数字列表
python将输入的n个数进行大小排序:小到大和大到小_灯火蓦然的博客-CSDN博客_python排序从大到小
#https://www.jb51.net/article/261970.htm
numList = input().split(' ') #将输入的一行数字按空格分割成列表
#https://blog.csdn.net/qdPython/article/details/120201005
numList = list(map(int, numList)) #将字符串数字列表转为数字列表,以便下面排序列表
#print(numList)
#https://blog.csdn.net/weixin_56817152/article/details/122431039
numList.sort(reverse=True) #将列表的值按从大到小的顺序排序
for i in numList: #打印结果,每个数字后一个空格
print(str(i)+" ",end="")
print(*sorted(map(int,input().split()),reverse=True))