PEP 308 use case (Re: A suggestion for a possible Python module)
Greg Ewing (using news.cis.dfn.de)
me at privacy.net
Mon Mar 10 23:30:38 EST 2003
If anyone's collecting potential use cases for
conditional expressions, here's one.
Jp Calderone wrote:
> def commaize(s):
> P = len(s) % 3
> st = s[:P] + (len(s) > 3 and P and ',' or '')
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> return st + ','.join([s[i:i+3] for i in range(P, len(s), 3)])
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list