1

I have a list l1 this is structured according to the scheme [(number1, number2), ... (number1n, number2n]. I would like to always only want the very first number and remove the brackets. How do I do that?

l1 = [(285, 1.0000001), (3614, 0.93460923), (671, 0.78742), (1351, 0.72903967), (3883, 0.6139718)]
l2 = [285, 3614, 671, 1351, 3883]
Ella
  • 361
  • 3
  • 9

1 Answers1

3

Try this:

l1 = [(285, 1.0000001), (3614, 0.93460923), (671, 0.78742), (1351, 0.72903967), (3883, 0.6139718)]


l2 = [i[0] for i in l1]

or

l2 = [i for i,j in l1]

Also you can do it with zip.

l2 = list(zip(*l1))[0]

Using map:

l2 = list(map(lambda x:x[0], l1)) 
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59