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
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
Cool, thanks for those answers, it's been too long since I wrote any python
code
2008/7/4 Rory Geoghegan <[EMAIL PROTECTED]>:
>
> 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:
> >
> > [Dar
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('/')
>> ['.', 'te
Because you requested one ;) If you did
>>> print args[-1]
you would get
'test.py'
The presence of a ':' in args[-1:] means you are requesting a sequence,
even if it contains a single item.
-Padraig
Darragh Sherwin wrote:
> Why does python return a list rather than a string in this case?
>
[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[-
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']
>>>
Thanks
Darragh
--~--~-~--~~~---~--~~
You received this message beca