我想排序一個隨機整數值的列表,如下所示:aList = [2241, 350]
從每個單獨整數的最後一個元素開始(將整數轉換爲字符串後)24 , 35 和排序爲空列表,像這樣:整數列表的整數值由個別整數值
zeros = [350]
ones = [2241]
twos = []
threes = []
fours = []
fives = []
sixes = []
sevens = []
eights = []
nines = []
然後返回一個組合列表,像這樣:aList = [350, 2241]
並遍歷它再次看整數中的下一個值並重復這個過程,直到列表按從小到大的整數排序。
這是我到目前爲止的代碼:
zeros, ones, twos, threes, fours, fives, sixes, sevens, eights, nines = [], [], [], [], [], [], [], [], [], []
for x in range(-1, 0) :
for val in aList :
val = str(val)
if val[x] == 0 :
zeros.append(val)
elif val[x] == 1 :
ones.append(val)
elif val[x] == 2 :
twos.append(val)
elif val[x] == 3 :
threes.append(val)
elif val[x] == 4 :
fours.append(val)
elif val[x] == 5 :
fives.append(val)
elif val[x] == 6 :
sixes.append(val)
elif val[x] == 7 :
sevens.append(val)
elif val[x] == 8 :
eights.append(val)
elif val[x] == 9 :
nines.append(val)
aList = zeros + ones + twos + threes + fours + fives + sixes + sevens + eights + nines
del zeros[:], ones[:], twos[:], threes[:], fours[:], fives[:], sixes[:], sevens[:], eights[:], nines[:]
return aList
它返回一個空列表。任何幫助表示讚賞,謝謝。
我究竟想你的答案是比約翰更正確Zwinck – dawg 2015-02-10 00:57:08