Actually, that's only a shallow copy:
>>> x = [1,2,['test'],'astring']
>>> x
[1, 2, ['test'], 'astring']
>>> y = x[:]
>>> y
[1, 2, ['test'], 'astring']
>>> y[2][0] = 'test2'
>>> y
[1, 2, ['test2'], 'astring']
>>> x
[1, 2, ['test2'], 'astring']
-Padraig
Rory Geoghegan wrote:
> Cool little known kludge:
>
> to do a deep-copy of list a, simply do:
>
> a[:]
>
> On Fri, Jul 4, 2008 at 2:48 PM, Alan Kennedy <[EMAIL PROTECTED]> wrote:
>> [Darragh]
>>> Why does python return a list rather than a string in this case?
>>>
>>>>>> mystr = "./test.py"
>>>>>> print mystr.split('/')
>>> ['.', 'test.py']
>>>>>> args = mystr.split('/')
>>>>>> print args[-1:]
>>> ['test.py']
>> Because you asked for a slice, by specifying two indices of the array,
>> e.g. args[-1:]
>>
>> If you just want a string, ask for an element
>>
>>>>> print args[-1]
>> 'test.py'
>>
>> HTH,
>>
>> Alan.
>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---