C pointers/Python
Lonnie Princehouse
finite.automaton at gmail.com
Tue Mar 22 15:08:35 EST 2005
"len" is a built-in function in Python, so you probably don't want to
use it as a variable name.
What is this C code actually trying to do? Don't try to transliterate
it; instead, read up on how lists and slicing work, and rewrite it in
Python starting from a higher level of abstraction.
One hint- you can copy the same datum many times without a while
loop...
# reassign sub-list interval [i, j-1]
buffer[i:j] = [data] * (j-i)
# reassign the entire list
buffer[:] = [data] * len(buffer)
More information about the Python-list
mailing list