Is there an easier way to express this list slicing?

Neil Cerutti horpner at yahoo.com
Thu Nov 30 14:25:52 EST 2006


On 2006-11-30, Neil Cerutti <horpner at yahoo.com> wrote:
> On 2006-11-30, John Henry <john106henry at hotmail.com> wrote:
>> If I have a list of say, 10 elements and I need to slice it into
>> irregular size list, I would have to create a bunch of temporary
>> variables and then regroup them afterwords, like:
>>
>> # Just for illustration. Alist can be any existing 10 element list
>> a_list=("",)*10
>> (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list
>> alist=(a,)
>> blist=(b,)
>> clist=(c1,c2,c3)
>> dlist=(d2,d3,d4,d5)
>>
>> That obviously work but do I *really* have to do that?
>
> Please post actual code we can run, rather than text that is
> almost, but not quite, entirely unlike Python code.

Ummm... that comment is withdrawn. :-O

-- 
Neil Cerutti



More information about the Python-list mailing list