如何在Python 3.6中按数字顺序对字符串列表进行排序?

时间:2018-08-19 22:20:54

标签: python sorting

我有以下代码:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'angelheap'
Error while executing Python code.

我要删除第一个元素,我想对其余元素进行排序 这就是我得到的:

x='10 0 17 5'
a = x.split(' ')
first = a.pop(0)
print(first)
print(a)
c  = a.sort(key=int)
print(c)

根据此帖子Sort a List of string by Numeric Order,我们希望看到“无”,我希望看到['0','5','17']。

为什么它不起作用?

更新

10
['0', '17', '5']
None

更新2

x='10 0 17 5'
a = x.split(' ')
first = a.pop(0)
print(first)
print(a)
c  = a.sort(key=int)
print(c)
d  = sorted(a)
print(d)
e  = sorted(a.items())
print(e)
//
10
['0', '17', '5']
None
['0', '17', '5']
Traceback (most recent call last):
  File "index.py", line 14, in <module>
    e  = sorted(a.items())
AttributeError: 'list' object has no attribute 'items'

0 个答案:

没有答案