Python lists
Hans Mulder
hansmu at xs4all.nl
Sun Dec 30 18:19:47 EST 2012
On 30/12/12 23:25:39, Evan Driscoll wrote:
> 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:
Oops, you're right.
>>>> 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)).
Thanks for correcting me,
-- HansM
More information about the Python-list
mailing list