Skip to content

Instantly share code, notes, and snippets.

@csytan
Created October 14, 2009 08:54
Show Gist options
  • Save csytan/209900 to your computer and use it in GitHub Desktop.
Save csytan/209900 to your computer and use it in GitHub Desktop.
evil uca sort
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