小编Aay*_*ush的帖子

对整数和字符串的混合列表进行排序

我试图排序以下混合的int和字符串列表,但改为获取TypeError.我想要的输出顺序是排序整数然后排序字符串.

x=[4,6,9,'ashley','drooks','chay','poo','may']
>>> x.sort()
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    x.sort()
TypeError: '<' not supported between instances of 'str' and 'int'
Run Code Online (Sandbox Code Playgroud)

python sorting mixed list python-3.x

-1
推荐指数
1
解决办法
1969
查看次数

标签 统计

list ×1

mixed ×1

python ×1

python-3.x ×1

sorting ×1