스트링 배열 정렬(sorting)하기 with Python
[파일명: testSort.py]------------------------------------------------
import sys
def printArray(a):
sys.stdout.write("[")
for i in range(0, len(a) - 1):
sys.stdout.write("%s, " % a[i])
if len(a) > 0:
sys.stdout.write("%s" % a[-1])
sys.stdout.write("]\n")
list = sys.argv[1::]
list.sort()
printArray(list)
------------------------------------------------
실행> python testSort.py one two three four five
[five, four, one, three, two]
실행> python testSort.py 하나 둘 셋 넷 다섯
[넷, 다섯, 둘, 셋, 하나]
IronPython으로 실행하기:
실행> ipy testSort.py one two three four five
[five, four, one, three, two]
실행> ipy testSort.py 하나 둘 셋 넷 다섯
[넷, 다섯, 둘, 셋, 하나]
Jython으로 실행하기:
실행> jython testSort.py one two three four five
[five, four, one, three, two]
( Jython으로 실행하는 경우, )
( 버전 2.2.1이든 2.5b3이든 명령행 옵션으로 넣어준 한글을 잘 처리하지 못한다. )
실행> jython testSort.py 하나 둘 셋 넷 다섯
[?, ??, ?, ?, ??]