Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58080

sorting german characters äöü...

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.xlned.com!news.astraweb.com!border2.a.newsrouter.astraweb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ml@fam-goebel.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'elif': 0.05; 'received:192.168.178': 0.07; "'')": 0.09; 'subject:characters': 0.09; 'def': 0.12; '120,': 0.16; 'b):': 0.16; 'goebel': 0.16; 'great!': 0.16; 'received:192.168.178.20': 0.16; 'sqlite': 0.16; 'things.': 0.19; 'header:User-Agent:1': 0.23; 'folgende': 0.24; 'compare': 0.26; 'function': 0.29; 'especially': 0.30; 'way?': 0.31; 'could': 0.34; 'german': 0.35; 'prepare': 0.35; 'but': 0.35; 'there': 0.35; 'alle': 0.36; 'should': 0.36; 'two': 0.37; 'handle': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'und': 0.40; 'received:217': 0.63; 'more': 0.64; 'subjectcharset:iso-8859-1': 0.66; 'st.': 0.69; 'intelligent': 0.74
Date Wed, 30 Oct 2013 19:38:42 +0100
From Ulrich Goebel <ml@fam-goebel.de>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0
MIME-Version 1.0
To python-list@python.org
Subject sorting german characters äöü...
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-Mailman-Approved-At Wed, 30 Oct 2013 19:39:14 +0100
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1823.1383158355.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383158355 news.xs4all.nl 15957 [2001:888:2000:d::a6]:52500
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58080

Show key headers only | View raw


Hello,

for a SQLite database I would like to prepare a collating function in 
python. It has to compare two (unicode-)strings s, t and should return 
-1 if s<t, 0 if s=t and 1 if s>t.

The strings are german names/words, and what I would like is to have a 
case-insensitive ordering, which treates

   ä as a
   ö as ö
   ü as ü
   ß as ss

and a few more things.

What I did is to "normalize" the two strings and then compare them:

def normal (s):
   r = s
   r = r.strip()   # wir entfernen führende und folgende Leerzeichen
   r = r.replace(u' ', '')    # wir entfernen alle Leerzeichen innerhalb
   r = r.replace(u'ß', u'ss')
   r = r.upper()   # alles in Großbuchstaben
   r = r.replace(u'Ä', u'A')   # Umlaute brauchen wir nicht...
   r = r.replace(u'Ö', u'O')   # "
   r = r.replace(u'Ü', u'U')   # "
   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

That works, but my be there is a more intelligent way? Especially there 
could be much more r.replace to handle all the accents as ^ ° ´ ` and so on.

Any ideas? That would be great!

Ulrich

-- 
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

sorting german characters äöü... Ulrich Goebel <ml@fam-goebel.de> - 2013-10-30 19:38 +0100

csiph-web