[ create a new paste ] login | about

Link: http://codepad.org/ZDqRxalc    [ raw code | output | fork ]

Python, pasted on Dec 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-

def ishangul(c):
    return 44032 <= ord(c) <= 55203

def hangulfirst(x, y):
    if not x or not y:
    	return cmp(x, y)

    xh = ishangul(x[0])
    yh = ishangul(y[0])
    if xh and not yh:
    	return -1
    elif not xh and yh:
        return +1
    else:
    	return cmp(x, y)

lst = [u'a', u'b', u'한글', u'가나다']
lst.sort(cmp=hangulfirst)
print u', '.join(lst).encode('utf8')


Output:
1
가나다, 한글, a, b


Create a new paste based on this one


Comments: