On Wed, Oct 20, 2021 at 11:35 AM Steven D'Aprano <st...@pearwood.info> wrote: > > On Wed, Oct 20, 2021 at 11:10:52AM +1100, Chris Angelico wrote: > > On Wed, Oct 20, 2021 at 11:02 AM Steven D'Aprano <st...@pearwood.info> > > wrote: > > > Ironically, Ricky's in-fun suggestion that we use the tilde operator for > > > swapcase was the only suggestion in these two threads that actually met > > > the invariant for an inverse that ~~x == x. > > > > > > > >>> x = "ß" > > > > :) Okay, so it's *mostly* an invariant. > > Hah, well spotted! > > Ironically, there is an uppercase eszett, 'ẞ', although font support for > it may still be limited. (Come on font designers, it has only been > official in Unicode since 2008 and in German orthography in 2017). >
Yes (and it shows up fine in both my web browser and my terminals), but that only makes swapcase worse. >>> s = "ẞ" >>> print(s := s.swapcase()) ß >>> print(s := s.swapcase()) SS >>> print(s := s.swapcase()) ss Fortunately, you can always rely on casefold to make things consistent: >>> "ẞ".casefold() == "ß".casefold() == "SS".casefold() == "ss".casefold() True TBH swapcase is a bit of a minefield if you don't know what language you're working with. >>> "Iİıi".swapcase() 'ii̇II' I'm not sure I've ever used it in production. Normally it's just upper(), lower(), or title() for conversions, and casefold() for comparisons. The most logical "negation" of a string would be reversing it, which WOULD be... well, reversible. But that doesn't need an operator, since it already has slice notation. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CKIDS5D2IUAW7P4GWZNFGTVYJIZY6WHP/ Code of Conduct: http://python.org/psf/codeofconduct/