From: Roberto V. <rvi...@mk...> - 2007-04-06 10:42:47
|
All -- In jython, if 'list1' is a list, should 'list2 = list( list1 )' provide a shallow copy as it does in python? At least in 2.1, it seems to provide just an alias. Assuming this isn't a bug (typically they aren't), can someone explain the difference in behavior? I don't seem to recall reading anything about it... Below are the same code for both jython and python: Jython 2.1 on java1.5.0_09 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> a = ['my', 'copy', 'test'] >>> a ['my', 'copy', 'test'] >>> b = list( a ) >>> b ['my', 'copy', 'test'] >>> a.reverse() >>> a ['test', 'copy', 'my'] >>> b ['test', 'copy', 'my'] >>> a is b 1 Python 2.4.4 (#2, Oct 20 2006, 00:23:25) [GCC 4.1.2 20061015 (prerelease) (Debian 4.1.1-16.1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = ['my', 'copy', 'test'] >>> a ['my', 'copy', 'test'] >>> b = list( a ) >>> b ['my', 'copy', 'test'] >>> a.reverse() >>> a ['test', 'copy', 'my'] >>> b ['my', 'copy', 'test'] >>> a is b False Roberto |