转换字符串列表 [ '3', '1', '2' ] 到已排序整数列表 [1, 2, 3]
我有一个字符串表示形式的整数列表,类似于以下内容:
L1 = ['11', '10', '13', '12',
'15', '14', '1', '3',
'2', '5', '4', '7',
'6', '9', '8']
我需要将其设为一个整数列表,例如:
L2 = [11, 10, 13, 12, 15, 14, 1, 3, 2, 5, 4, 7, 6, 9, 8]
最后我将按如下方式对其进行排序:
L3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] # by L2.sort()
请让我知道从 L1 获取的最佳方式是什么
到 L3
?
I have a list of integers in string representation, similar to the following:
L1 = ['11', '10', '13', '12',
'15', '14', '1', '3',
'2', '5', '4', '7',
'6', '9', '8']
I need to make it a list of integers like:
L2 = [11, 10, 13, 12, 15, 14, 1, 3, 2, 5, 4, 7, 6, 9, 8]
Finally I will sort it like below:
L3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] # by L2.sort()
Please let me know what is the best way to get from L1
to L3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样一步完成:
更详细地说,步骤如下:
You could do it in one step like this:
In more detail, here are the steps: