Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58108 > unrolled thread
| Started by | Ulrich Goebel <ml@fam-goebel.de> |
|---|---|
| First post | 2013-10-30 21:17 +0100 |
| Last post | 2013-10-30 21:17 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: sorting german characters äöü... solved Ulrich Goebel <ml@fam-goebel.de> - 2013-10-30 21:17 +0100
| From | Ulrich Goebel <ml@fam-goebel.de> |
|---|---|
| Date | 2013-10-30 21:17 +0100 |
| Subject | Re: sorting german characters äöü... solved |
| Message-ID | <mailman.1838.1383164370.18130.python-list@python.org> |
Hi,
Am 30.10.2013 19:48, schrieb Skip Montanaro:
> Perhaps this? http://stackoverflow.com/questions/816285/where-is-pythons-best-ascii-for-this-unicode-database
There I found the module unidecode
(http://pypi.python.org/pypi/Unidecode),
and I found it very helpful. Thanks a lot!
So my function normal() now looks like this:
from unidecode import unidecode
def normal (s):
r = s
r = r.strip() # take away blanks at the ends
r = r.replace(u' ', '') # take away all other blanks
r = unidecode(r) # makes the main work
# - see the docu of unidecode
r = r.upper() # changes all to uppercase letters
return r
def compare (a, b):
aa = normal(a)
bb = normal(b)
if aa < bb:
return -1
elif aa == bb:
return 0
else:
return 1
For the "normal" cases, that works quiet perfect - as I want it to do.
For more (extreme) difficult cases there are even limits, but they are
even wide limits, I would say. For example,
print normal(u'-£-¥-Ć-û-á-€-Đ-ø-ț-ff-ỗ-Ể-ễ-ḯ-ę-ä-ö-ü-ß-')
gives
-PS-Y=-C-U-A-EU-D-O-T-FF-O-E-E-I-E-A-O-U-SS-
That shows a bit of what unidecode does - and what it doesn't.
> There is also a rather long-ish recent topic on a similar topic that
> might be worth scanning as well.
Sorry, I didn't find that.
> I've no direct/recent experience with this topic. I'm just an
> interested bystander.
But even a helpful bystander. Thank You!
Ulrich
--
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn
Back to top | Article view | comp.lang.python
csiph-web