How to convert a List with two capsuled tuples insed it to list?

Issue

I have a list which has capsuled two tuples inside of it.

Example:

[(('100.100.100.100', 11111), ('100.100.100.100', 11111))]

And I need to convert it like this:

['100.100.100.100', '100.100.100.100']

Thanks for the help!

Solution

Use a comprehension:

l1 = [(('100.100.100.100', 11111), ('100.100.100.100', 11111))]
l2 = [l[0] for l in l1[0]]
print(l2)

# Output:
['100.100.100.100', '100.100.100.100']

Answered By – Corralien

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published