有没有一种方法可以对列表中的数字进行坐标处理?

时间:2019-12-25 18:18:41

标签: python python-3.x list random numbers

我正在开发一个名为“ tombola”的台式游戏机(我不知道英文名字)。 该代码为我提供了一个数字列表:

['22', '25', '75', '52', '70', '14', '5', '60', '81', '83', '72', '2', '36', '78', '10', '65', '43', '74', '51', '9', '29', '49', '24', '76', '23', '67', '35', '8', '85', '59', '18', '66', '38', '27', '19', '57', '77', '42', '84', '11', '46', '13', '89', '62', '7', '39', '32', '50', '86', '44', '64', '79', '54', '12', '68', '34', '15', '69', '71', '45', '20', '41', '82', '16', '1', '48', '37', '58', '61', '56', '53', '40', '80', '31', '87', '73', '90', '3', '88', '55', '30', '21', '4', '63', '26', '28', '33', '6', '17']

我需要以新月形方式对这些数字进行坐标处理,并具有如下所示的输出:

['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90']

1 个答案:

答案 0 :(得分:1)

似乎您有一个字符串列表,并且想要按数字对其进行排序。为此,您需要告诉sort它需要对每个元素进行排序,就好像它是一个int一样。

my_nums = ['22', '25', '75', '52', '70', '14', '5', '60', '81', '83', '72', '2', '36', '78', '10', '65', '43', '74', '51', '9', '29', '49', '24', '76', '23', '67', '35', '8', '85', '59', '18', '66', '38', '27', '19', '57', '77', '42', '84', '11', '46', '13', '89', '62', '7', '39', '32', '50', '86', '44', '64', '79', '54', '12', '68', '34', '15', '69', '71', '45', '20', '41', '82', '16', '1', '48', '37', '58', '61', '56', '53', '40', '80', '31', '87', '73', '90', '3', '88', '55', '30', '21', '4', '63', '26', '28', '33', '6', '17']
my_nums.sort(key=int)
print(my_nums)

输出

['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90']