Re: [Tutor] Accesing "column" of a 2D list

2007-08-21 Thread Kent Johnson
Ian Witham wrote: > This looks like a job for List Comprehensions! > > >>> list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] > >>> new_list = [item[1] for item in list] > >>> new_list > [2, 5, 8] > >>> Alternately, if you want *all* columns, you can use zip() to transpose the lists: In [1]: lst = [[

Re: [Tutor] Accesing "column" of a 2D list

2007-08-20 Thread Ian Witham
This looks like a job for List Comprehensions! >>> list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> new_list = [item[1] for item in list] >>> new_list [2, 5, 8] >>> looks good? Ian On 8/21/07, Orest Kozyar <[EMAIL PROTECTED]> wrote: > > I've got a "2D" list (essentially a list of lists where all su

[Tutor] Accesing "column" of a 2D list

2007-08-20 Thread Orest Kozyar
I've got a "2D" list (essentially a list of lists where all sublists are of the same length). The sublists are polymorphic. One "2D" list I commonly work with is: [ [datetime object, float, int, float], [datetime object, float, int, float], [datetime object, float, int, float] ] I'd like to