"Emad Nawfal (عماد نوفل)" <[email protected]> wrote

As a linguist, I would love to know what the difference between these
things are:

The differences are the same whether you are a linguist or not :-)
(and yes I know my reading is incorrect grammaticallly but I couldn't resist it!)

mycopy = original[:]
Returns a slice of the original list. In this case it so happens
the slice is the full list.

mycopy = copy.deepcopy(original)

calls the deepcopy function which traverses the original list
and all nested structures explicitly copying the elements.

mycopy = list(original)

Use the list type constructor to make a list out of its argument.
It just so happens the argument in this case is a list.

The end result is the same but the mechanisms (ie the code called)
are quite different. It would be interesting to compare speeds,
but I'm too lazy! I suspect deepcopy would be slowest but I'm
not sure about the other two.

Alan G.



_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to