manipulating lists to find different variables

The following is the first line from my list l:

 [0.0, 753.128, 990.43, 686.832, 366.922, -93.454, 1.0]

This is the result of:

 print l[0]

I want to take all the first element from all such *lines of my list and assign them to another list. How can I do it in python?


Using a list comprehension:

lists = [[1,2,3], [4,5,6]]
[ l[0] for l in lists ]

That would do it. Nicer is to use map: you map a list of lists to a list of their heads:

map( lambda l: l[0], lists )

If performance is important, you may want to create an iterator over the heads of your lists:

heads = itertools.imap( lambda l: l[0], enumerate(lists))

for head in heads:
   print head 

Need Your Help

Using Return In another method


In the code snippet below I have created a Guid which I also want to use in other method:

How to change the background color of a non-visible item in ListView in Android

android listview android-listview background navigation-drawer

I’m trying to make a navigation drawer that changes the background color of items in a ListView based on integers received from another part of the application – i.e. not based on what item is clic...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.