which methods to use?

s99999999s2003 at yahoo.com s99999999s2003 at yahoo.com
Thu Mar 29 03:16:31 CEST 2007


On Mar 29, 8:25 am, Florian Leitner <fleit... at REMcnioOVE.es> wrote:
> * s99999999s2... at yahoo.com wrote, On 3/29/07 2:09 AM:
>
> >   hi
> > which is the best methods to use for list copying. using list() , [:]
> > or create list through list comprehension. what are the differences
> > between these ?
> > thanks
>
> depends on what you intend to do:
>
> -create a new object:
> use a list comprehension or list()
>
> -make a shallow copy:
> use copy.copy() or the slicing operator ([:])
>
> -make a deep copy (incl. each list element):
> use copy.deepcopy()
>
> Try experimenting around, deleting and adding elements or changing them
> in the copy of your list and the original and see what happens if you
> are not sure what these things do. (to use copy, import it first)
>
> flo

thanks.
what do you mean by create new object when using list comprehensoin or
list()? Does using slicing create a new object as well?




More information about the Python-list mailing list