Beginner question - How to effectively pass a large list
Donn Cave
donn at drizzle.com
Sat Dec 20 01:05:02 EST 2003
Quoth Jp Calderone <exarkun at intarweb.us>:
| On Thu, Dec 18, 2003 at 03:29:55PM -0800, Asun Friere wrote:
...
|> What surprised me was that the facially equivalent:
|> >>> def f (d=[]) :
|> ... d += [0]
|> ... print d
|> did not do so. Apparently '+=' in regards to lists acts like
|> list.apppend, rather than as the assignment operator it looks like.
|
| list.extend, to be more precise, or list.__iadd__ to be completely precise
| :) The maybe-mutate-maybe-rebind semantics of += lead me to avoid its use
| in most circumstances.
This tacky feature certainly ought to be considered for the
chopping block in version 3, for exactly that reason.
Donn Cave, donn at drizzle.com
PS. Good analysis, JR, I learned something from it.
More information about the Python-list
mailing list