what is this?
Huayang Xia
huayang.xia at gmail.com
Thu Jan 4 12:02:28 EST 2007
Sequence slicing [starting-at-index : but-less-than-index [ : step]].
Start defaults to 0, end to len(sequence), step to 1.
So l[i::rows] means: slicing start from i, ending with len(l) and step
with rows. So function colsplit(l, cols) returns a list of sequence
with conversion of:
Assume cols = 4:
From:
ABCD
ABCD
ABCD
AB
To:
AAAABBBBCCCDDD
On Jan 4, 11:42 am, "Eric Price"
<soyouthinkimgonnaliket... at hotmail.com> wrote:
> Hello;
> I'm studying some code examples from the python cookbook site. I came across
> this:
>
> def colsplit(l, cols):
> rows = len(l) / cols
> if len(l) % cols:
> rows += 1
> m = []
> for i in range(rows):
> m.append(l[i::rows])
> return m
>
> What I'd like to know is what is the double colon? What does it do?
> m.append(l[i::rows])
>
> Thanks,
> Eric
>
> _________________________________________________________________
> Type your favorite song. Get a customized station. Try MSN Radio powered
> by Pandora.http://radio.msn.com/?icid=T002MSN03A07001
More information about the Python-list
mailing list