【问题标题】:How to convert a List with two capsuled tuples insed it to list?如何将包含两个封装元组的列表转换为列表?
【发布时间】:2021-12-25 13:56:14
【问题描述】:

我有一个列表,其中包含两个元组。

例子:

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

我需要像这样转换它:

['100.100.100.100', '100.100.100.100']

感谢您的帮助!

【问题讨论】:

    标签: python list type-conversion tuples


    【解决方案1】:

    使用理解:

    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']
    

    【讨论】:

    • 非常感谢!
    • @Ch3steR,感谢编辑!
    • @Corralien 没问题。 :)
    猜你喜欢
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    相关资源
    最近更新 更多