-1

I have list:

[[(5, 0.13074668991267904), (7, 0.50480936593447379), (11, 0.24881894415284611)]
[(19, 0.2984135829981458), (24, 0.31341486626464521), (29, 0.15972991970724332), (31, 0.12844163102996534)]]

I need to create a new list with second values from previous list, which have to look like:

[[0.13074668991267904, 0.50480936593447379, 0.24881894415284611)]
 [0.2984135829981458, 0.31341486626464521, 0.15972991970724332), 0.12844163102996534)]]

How can I do that?

Andy G
  • 19,232
  • 5
  • 47
  • 69
Alex Savin
  • 215
  • 1
  • 4
  • 12

1 Answers1

1

You can just iterate over the original list(s) grabbing the last element in each as one option.

new_list = [[x[-1] for x in a_list] for a_list in nested_lists]
Pythonista
  • 11,377
  • 2
  • 31
  • 50