Python lists
Evan Driscoll
driscoll at cs.wisc.edu
Sun Dec 30 17:25:39 EST 2012
On 12/30/2012 4:19 PM, Hans Mulder wrote:
> If it's okay to modify the original list, you can simply do:
>
> l[0] = split(l[0], ", ")
>
> If modifying the original is not okay, the simple solution would
> be to copy it first:
>
> l2 = l
> l2[0] = split(l2[0], ", ")
Um, that doesn't copy the list:
>>> l = ["C100, C117", "X7R ..."]
>>> l2 = l
>>> import string
>>> l2[0] = string.split(l2[0], ", ")
>>> l
[['C100', 'C117'], 'X7R ...']
>>> l2
[['C100', 'C117'], 'X7R ...']
To make a copy of a list you can either use slice syntax (l2 = l[:]) or
call the list constructor (l2 = list(l)).
Evan
>
>
> Hope this helps,
>
> -- HansM
>
>
More information about the Python-list
mailing list