[CentralOH] chr()/ord() Ugliness

Thomas Winningham winningham at gmail.com
Mon Nov 11 19:37:06 CET 2013


just wanted to add how my subconscious wants to solve this if i were doing
it:

characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
character_relation = lambda c,i : characters[(characters.index(c.upper()) +
i)%26]

>>> character_relation("a",3)
'D'
>>> character_relation("a",-2)
'Y'

anyway... i want to say the talk about encoding and such really gets to the
point of how old ascii tricks are somewhat inapplicable to our new unicode
world. anyway... fun stuff.




On Mon, Nov 11, 2013 at 10:41 AM, Eric Floehr <eric at intellovations.com>wrote:

>
> string.uppercase returns a string of all the capital letters in ASCII.
>>
>
> string.uppercase is locale-dependent, so while in most locales it will be
> ASCII, it won't in all locales.
>
> Because of that fact (i.e. a constant that changes :-), string.uppercase
> (and lowercase and letters) have been removed from Python 3.
>
> So if you want something that works on Python 2 and 3, you'll need to use
> ascii_uppercase (or ascii_lowercase or ascii_letters).
>
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20131111/8c040448/attachment.html>


More information about the CentralOH mailing list