PEP 308 original proposal "used" already in Python Documentation

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Mon Mar 10 21:24:51 EST 2003


Jon Perez wrote:
> Now how would we express setdefault() using the ternary
> operator though?

No problem, we just indulge in a bit of listcomp-abuse:

   a[k] if k in a else [y for y in x if operator.setitem(a, k, y) or 1][0]

:-)

-- 
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