Raymond Hettinger added the comment:
Sorry, the text needs to stand as-is.
It is supposed to be a hint of what can be done,
nothing more.
The technique of t=x; x=y; y=t is somewhat basic
and has general applicability -- there's nothing
"complex" about it. Also, for short strings
such as the
samwyse added the comment:
The text in question is also talking about the problems with using 'replace' to
swap pairs of characters, so a better, alternate, process would be valuable,
especially for anyone unaware of the translate method.
--
___
Py
R. David Murray added the comment:
The text in question is talking about 'replace' as a general mechanism for
'fixing' the separator character, and as such I don't think introducing
translate would enhance the exposition. I suppose it could be added in a
footnote.
--
nosy: +eric.smi
New submission from samwyse :
PEP 378 states;
format(n, "6,f").replace(",", "X").replace(".", ",").replace("X", ".")
This is complex and relatively slow. A better technique, which IMHO the
proposal should high-lighted, would be:
swap_commas_and_periods = bytes.maketrans(b',.', b'.,')
f