Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50962
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <devyncjohnson@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.054 |
| X-Spam-Evidence | '*H*': 0.89; '*S*': 0.00; 'algorithm': 0.04; 'string.': 0.05; '"""': 0.07; '(especially': 0.07; 'collier': 0.09; 'converts': 0.09; 'sentence': 0.09; 'tackle': 0.09; 'programs.': 0.14; 'comparison"': 0.16; 'earlier.': 0.16; 'letters.': 0.16; 'lowercase': 0.16; 'perfect.': 0.16; 'those,': 0.16; 'varies': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'subject:Code': 0.24; 'unicode': 0.24; 'helpful': 0.24; 'options': 0.25; 'compare': 0.26; 'equivalent': 0.26; 'first,': 0.26; 'second': 0.26; 'header:In- Reply-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; 'am,': 0.29; 'characters': 0.30; 'code': 0.31; 'received:10.0.0': 0.31; '>>>>': 0.31; 'context.': 0.31; "d'aprano": 0.31; 'option.': 0.31; 'steven': 0.31; 'figure': 0.32; 'skip:c 30': 0.32; 'url:python': 0.33; 'everyone': 0.33; 'are:': 0.33; '"the': 0.34; "can't": 0.35; 'something': 0.35; 'german': 0.35; 'johnson': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'described': 0.36; 'thanks': 0.36; 'received:10.0': 0.36; 'similar': 0.36; 'url:org': 0.36; 'example,': 0.37; 'two': 0.37; 'received:10': 0.37; 'implement': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'according': 0.40; 'even': 0.60; 'remove': 0.60; 'dave': 0.60; 'worry': 0.60; 'most': 0.60; 'hope': 0.61; 'new': 0.61; 'url:3': 0.61; 'range': 0.61; 'simply': 0.61; 'simple': 0.61; 'making': 0.63; 'more': 0.64; '20,': 0.68; 'combining': 0.68; 'hints': 0.68; 'containing': 0.69; 'jul': 0.74; 'future,': 0.83; '3.13': 0.84; 'characters,': 0.84; "d'aprano)": 0.84; 'ideas.': 0.84; 'angel': 0.91; 'treatment': 0.95; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=tEErypd7cc9+amMU/P94FXrhOLwl8xxMgovfZIoBPfw=; b=H431HzcWg8oitwpbM8+d+ThRdnv4CyR9kLCG3oH7hkJXm2j12JtcNA21/GDX1oQ04e VOHrSTr/4uQUIBu86mcoqrq1NoDybRb2vkKHCdIxqxXaKY0mwNGIWrs/LxA4BlHDqhsg Flb4bwR7SFdRDdK2aCKwGujO4Nz5dES9/W5fWGZ00prailpQsvmuXExQUUiyEwAcv+Ij yJ0b8g6fnjV+byeQA2AdOFECusut/VQGQBamdKH+cM4GPylNmkZrUvd0gu+HtW0HB5cY fCBYNTy9KVzgvtIRLmX/CwUJ81iJgidoVt1hB6SuQE4Ez16yjAx83+84dy+Ky6//VYlo k8DA== |
| X-Received | by 10.43.84.131 with SMTP id ak3mr13270500icc.84.1374322832747; Sat, 20 Jul 2013 05:20:32 -0700 (PDT) |
| Date | Sat, 20 Jul 2013 08:20:30 -0400 |
| From | Devyn Collier Johnson <devyncjohnson@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| To | Python Mailing List <python-list@python.org> |
| Subject | Re: Share Code Tips |
| References | <mailman.4868.1374241904.3114.python-list@python.org> <51e97e6e$0$29971$c3e8da3$5496439d@news.astraweb.com> <51E9B8EB.5060007@Gmail.com> <kscgv5$gv9$1@ger.gmane.org> <51E9E237.2040903@Gmail.com> <CAPTjJmqf1XvbwbXkhHKJA0OtM5tiXXmw9d3u8oLcsHrWXL=y-g@mail.gmail.com> |
| In-Reply-To | <CAPTjJmqf1XvbwbXkhHKJA0OtM5tiXXmw9d3u8oLcsHrWXL=y-g@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4918.1374322837.3114.python-list@python.org> (permalink) |
| Lines | 62 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374322837 news.xs4all.nl 15888 [2001:888:2000:d::a6]:33262 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50962 |
Show key headers only | View raw
On 07/19/2013 09:13 PM, Chris Angelico wrote: > On Sat, Jul 20, 2013 at 11:04 AM, Devyn Collier Johnson > <devyncjohnson@gmail.com> wrote: >> On 07/19/2013 07:09 PM, Dave Angel wrote: >>> On 07/19/2013 06:08 PM, Devyn Collier Johnson wrote: >>>> >>>> On 07/19/2013 01:59 PM, Steven D'Aprano wrote: >>> >>> <snip> >>>> >>>> As for the case-insensitive if-statements, most code uses Latin letters. >>>> Making a case-insensitive-international if-statement would be >>>> interesting. I can tackle that later. For now, I only wanted to take >>>> care of Latin letters. I hope to figure something out for all characters. >>>> >>> Once Steven gave you the answer, what's to figure out? You simply use >>> casefold() instead of lower(). The only constraint is it's 3.3 and later, >>> so you can't use it for anything earlier. >>> >>> http://docs.python.org/3.3/library/stdtypes.html#str.casefold >>> >>> """ >>> str.casefold() >>> Return a casefolded copy of the string. Casefolded strings may be used for >>> caseless matching. >>> >>> Casefolding is similar to lowercasing but more aggressive because it is >>> intended to remove all case distinctions in a string. For example, the >>> German lowercase letter 'ß' is equivalent to "ss". Since it is already >>> lowercase, lower() would do nothing to 'ß'; casefold() converts it to "ss". >>> >>> The casefolding algorithm is described in section 3.13 of the Unicode >>> Standard. >>> >>> New in version 3.3. >>> """ >>> >> Chris Angelico said that casefold is not perfect. In the future, I want to >> make the perfect international-case-insensitive if-statement. For now, my >> code only supports a limited range of characters. Even with casefold, I will >> have some issues as Chris Angelico mentioned. Also, "ß" is not really the >> same as "ss". > Well, casefold is about as good as it's ever going to be, but that's > because "the perfect international-case-insensitive comparison" is a > fundamentally impossible goal. Your last sentence hints as to why; > there is no simple way to compare strings containing those characters, > because the correct treatment varies according to context. > > Your two best options are: Be case sensitive (and then you need only > worry about composition and combining characters and all those > nightmares - the ones you have to worry about either way), or use > casefold(). Of those, I prefer the first, because it's safer; the > second is also a good option. > > ChrisA Thanks everyone (especially Chris Angelico and Steven D'Aprano) for all of your helpful suggests and ideas. I plan to implement casefold() in some of my programs. Mahalo, DCJ
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 09:51 -0400
Re: Share Code Tips Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-19 17:59 +0000
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 18:08 -0400
Re: Share Code Tips Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-20 03:18 +0000
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 06:07 -0400
Re: Share Code Tips Chris Angelico <rosuav@gmail.com> - 2013-07-20 09:08 +1000
Re: Share Code Tips Dave Angel <davea@davea.name> - 2013-07-19 19:09 -0400
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 21:04 -0400
Re: Share Code Tips Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-20 03:44 +0000
Re: Share Code Tips David Hutto <dwightdhutto@gmail.com> - 2013-07-20 00:15 -0400
Re: Share Code Tips David Hutto <dwightdhutto@gmail.com> - 2013-07-20 00:22 -0400
Re: Share Code Tips David Hutto <dwightdhutto@gmail.com> - 2013-07-20 00:26 -0400
Re: Share Code Tips David Hutto <dwightdhutto@gmail.com> - 2013-07-20 00:27 -0400
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 06:10 -0400
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:36 -0400
Re: Share Code Tips Chris Angelico <rosuav@gmail.com> - 2013-07-20 11:13 +1000
Re: Share Code Tips Dave Angel <davea@davea.name> - 2013-07-19 21:51 -0400
Re: Share Code Tips David Hutto <dwightdhutto@gmail.com> - 2013-07-19 23:42 -0400
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 06:06 -0400
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:20 -0400
csiph-web