0

I have this list:

[('5.333333333333333', 'n04'), ('5.0', 'n01'), ('3.9936507936507932', 'n03'), ('2.4206349206349205', 'n05'), ('1.9629629629629628', 'n02')]

and I like to have the list like this:

[n04, n01, n03, n02, n04]

how to do it? I have spend too many houres on this problem. Help please!

Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34
amb_ols
  • 1
  • 3

2 Answers2

0

Try:

x,y=zip(*[('5.333333333333333', 'n04'), ('5.0', 'n01'), ('3.9936507936507932', 'n03'), ('2.4206349206349205', 'n05'), ('1.9629629629629628', 'n02')])
y=list(y)
print(y)

Outputs:

['n04', 'n01', 'n03', 'n05', 'n02']
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34
0

You can use a list comprension to iterate over the list and pick out the values you are interested in and put them in a new list

my_list = [('5.333333333333333', 'n04'), ('5.0', 'n01'), ('3.9936507936507932', 'n03'), ('2.4206349206349205', 'n05'), ('1.9629629629629628', 'n02')]
my_new = [item[1] for item in my_list]
print(my_new)

OUTPUT

['n04', 'n01', 'n03', 'n05', 'n02']
Chris Doyle
  • 10,703
  • 2
  • 23
  • 42