Sequence-spreading
Rikard Bosnjakovic
rikbo716 at student.liu.se
Tue Mar 20 03:36:15 EST 2001
Hi.
I made a small spreading-sequence with the following code:
------
arg = "some string"
pm = 3
offsets = []
for i in xrange(pm):
everyX = filter(lambda y: not divmod(y, pm)[1], range(len(arg)))
added = map(lambda x: x+i, everyX)
offsets.append(filter(lambda x: x<len(arg), added))
print offsets
------
which gives the correct result:
>>> ## working on region in file /usr/tmp/python-3115DCp...
[[0, 3, 6, 9], [1, 4, 7, 10], [2, 5, 8]]
"pm" is the number of sequences, and then the sequences are increasing.
0 in first, 1 in second, 2 in third, 3 in first and so on, until the
length of the string 'arg' is reached. However, the loop-code is pretty
unreadable and awkward.
Anyone got a better solution for it?
--
Rikard Bosnjakovic - http://a214.ryd.student.liu.se/cv/ - ICQ: 1158217
Anyone sending unwanted advertising e-mail to my address will be
charged $250 for network traffic and computing time. By extracting my
address from this message or its header, you agree to these terms.
More information about the Python-list
mailing list