Home > Software engineering >  Removing tuple from nested list with tuple and lists
Removing tuple from nested list with tuple and lists

Time:03-03

I have a nested output in the form of this:

[(3, [['Avg_Order_Insert_Size', '572.9964086553654'], ['Avg_Order_Insert_Size', '34.858670832934195'], 
['Avg_Order_Insert_Size', '22.09531308137768']])]

And I want to get rid of the int (3) which is in a tuple, and save the lists containing strings and ints.

How do I accomplish this in the best way?

My goal is to use the lists within the tuple for creating a dictionary later on, but while these ints are there within the tuple I don't know what to do. Basically I think I want an output such as:

[([['Avg_Order_Insert_Size', '572.9964086553654'], ['Avg_Order_Insert_Size', '34.858670832934195'], 
['Avg_Order_Insert_Size', '22.09531308137768']])]

CodePudding user response:

I think this is enough:

>>> value = [(3, [['Avg_Order_Insert_Size', ...
>>> value[0] = value[0][1:]
>>> value
    [([['Avg_Order_Insert_Size', '572.9964086553654'], ['Avg_Order_Insert_Size', '34.858670832934195'], ['Avg_Order_Insert_Size', '22.09531308137768']],)]
  • Related