Created
October 14, 2009 08:54
-
-
Save csytan/209900 to your computer and use it in GitHub Desktop.
evil uca sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import urllib | |
def uca_sort(l, locale='en', _re_nums=re.compile('<tt class="count">(\d+):</tt>')): | |
"""Uses the ICU demo site to sort a list""" | |
url = 'http://demo.icu-project.org/icu-bin/locexp' | |
url += '?_=' + locale + '&d_=en&x=col' | |
data = 'str=' + '\n'.join(l) | |
html = urllib.urlopen(url, data).read() | |
all_nums = re_nums.findall(html) | |
sorted_nums = all_nums[len(l):] | |
sorted_nums = [int(n) - 1 for n in sorted_nums] | |
return [l[i] for i in sorted_nums] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment