how to refer to partial list, slice is too slow?

人言落日是天涯,望极天涯不见家 kelvin.you at gmail.com
Fri May 11 01:50:31 EDT 2007


I'm a python newbie. It seems the slice operation will do copy.
for example:
>>> a = [1,2,3,4,5,6,7,8,9,0]
>>> b = a[7:]
>>> b
[8, 9, 0]
>>> a.remove(9)
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 0]
>>> b
[8, 9, 0]

if the list have large members, the slice operations will consume many
times.
for instance, I have a long string named it as S, the size is more
than 100K
I want to parser it one part-to-part. first, I process the first 100
byte, and pass the remainder to the next parser function. I pass the
S[100:] as an argument of the next parser function. but this operation
will cause a large bytes copy. Is there any way to just make a
reference to the remainder string not copy?




More information about the Python-list mailing list