list[] = var => list.append(var) (phpstyle)

Nick Perkins nperkins7 at home.com
Mon Jul 16 20:52:15 EDT 2001


"Erno Kuusela" <erno-news at erno.iki.fi> wrote in message
news:kuzoa4hf75.fsf at lasipalatsi.fi...
>

> [reformatted for your reading pleasure]

* Incorrectly!!


>
> In article <9iqlgi$kbg9g$1 at ID-11957.news.dfncis.de>, "Emile van
> Sebille" <emile at fenx.com> writes:
>
> || "Alex Martelli" <aleaxit at yahoo.com> wrote in message
>
> || "Nick Perkins" <nperkins7 at home.com> wrote in message
> || news:LF447.476898$eK2.98947068 at news4.rdc1.on.home.com...
>

* Just for the record, I (Nick Perkins) did not write any of this.
* I responded to it.

> ||| I think it should be neet if it would be possible to append a variable
> ||| to a list by just using
> ||| list_var[] = var_to_append
> ||| It works that way in PHP and I think it's nice.
> |||
> ||| Any comments?
>
> ||    list_var += var_to_append
> ||
> || (which is how you express this today in Python) is equivalent
> || and shorter.  Python does NOT go out of its way to provide
> || a zillion ways to write the same, identical thing.
>
> | Alex is right as long as var_to_append is already a list.
>
> not quite:
>
> >>> l1 = [1]
> >>> l2 = [2]
> >>> l1 += l2
> >>> l1
> [1, 2]
>
> vs.
>
> >>> l2.append(l1)
> >>> l2
> [2, [1]]
>
> | For non-lists though you can also do
>
> | list_var += 1,
>
> | or,
>
> | list_var += (1,)
>
> hmm, does the sequence protocol really include __add__ing arbitrary
> sequences? one would think lists would support it too if that
> was the case.
>
>   -- erno





More information about the Python-list mailing list