Dave Angel <da...@ieee.org> wrote: > > > Esmail wrote: >> <div class="moz-text-flowed" style="font-family: -moz-fixed">Diez B. >> Roggisch wrote: >>> Esmail schrieb: >>>> Could someone help confirm/clarify the semantics of the [:] operator >>>> in Python? >>>> >>>> a = range(51,55) >>>> >>>> ############# 1 ################## >>>> b = a[:] # b receives a copy of a, but they are independent >>> > >>>> >>>> <snip> >> <snip> > (1) is most appropriate in that case. In fact, unless there is other > code mixed in between, it's always the most appropriate.
An alternative view is that it is most appropriate to do: b = list(a) as that accepts any type of sequence for a and you don't have to remember obscure punctuation to know what it does. The exception of course is when (a) 'a' is sliceable and (b) you need to 'b' to be of the same type as 'a'. -- http://mail.python.org/mailman/listinfo/python-list