2014-01-29 64 views
-5

我的文件中包含像文件排序內容

1ajith 
3abhiram 
9bijo 
2aaliya 
etc.. 

我想對它進行排序約1602元。我期望的輸出是:

1ajith 
2aaliya 
3abhiram  
9bijo 

Plz幫助我提出寶貴的想法。

+0

你想使用[自然排序(http://stackoverflow.com/questions/5167928/what-is-natural-ordering-when-we-談論分類)還是簡單的詞典排序? –

+0

您是否嘗試過從命令行輸入排序? – perreal

+0

嘗試查看右側的一些_相關問題_。 – devnull

回答

0

應該是這樣的:

ins = open("file.txt", "r") 
array = [] 
for line in ins: 
    array.append(line) 
ins.close() 
array = sorted(array) 
for line in array : 
    print line