Steven skrev:

> For the purposes of this question, the list will be:
>
> t = [ "a", "b", "c", "n", "a", "a", "t", "t", "t" ]
>
> Now, I know that every 3rd element of the list belongs together:
>
> Group 1 = 0, 3, 6
> Group 2 = 1, 4, 7
> Group 3 = 2, 5, 8
>
> I'm trying to sort this list out so that I get a list of lists 
> that contain the correct elements:
>
> Goal = [ [ "a", "n", "t"], [ "b", "a", "t"],
> ["c", "a", "t" ] ]

#v+

>>> t = [ "a", "b", "c", "n", "a", "a", "t", "t", "t" ]
>>> [t[i::3] for i in range(3)]
[['a', 'n', 't'], ['b', 'a', 't'], ['c', 'a', 't']]
>>> 

#v-

Cheers,

-- 
Klaus Alexander Seistrup
SubZeroNet, Copenhagen, Denmark
http://magnetic-ink.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to