我正在尝试对阵列的串联列表进行排序

发布于 2025-02-09 02:38:21 字数 283 浏览 1 评论 0原文

我正在尝试对我的代码进行排列列表的串联列表

k1 = 15 19 3
k2 = 12 13

k1 = input().split()
k2 = input().split()
l = k1 + k2
x = l . sort()
print(x)

输出是['12','13','15','19','3'] 我不知道为什么3号在执行升序后最后结束。 我希望第三排在上升顺序上 请给出正确的代码

I am trying to sort a concatenated list of arrays

k1 = 15 19 3
k2 = 12 13

my code is :

k1 = input().split()
k2 = input().split()
l = k1 + k2
x = l . sort()
print(x)

the output is ['12', '13', '15', '19', '3']
I do not know why the number 3 ends last after doing ascending order.
i want the number 3 placed first in ascending order
kindly give the correct code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如此安好 2025-02-16 02:38:22

您有一个字符串列表,这些字符处按字母顺序排序。如果您想要一个INT列表,这些int列表会被数字排序,请这样做:

x = sorted(int(n) for _ in range(2) for n in input().split())
print(x)

为您提供:

15 19 3
12 13
[3, 12, 13, 15, 19]

You have a list of strings, which get sorted alphabetically. If you want a list of ints, which get sorted numerically, do:

x = sorted(int(n) for _ in range(2) for n in input().split())
print(x)

which gives you:

15 19 3
12 13
[3, 12, 13, 15, 19]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文