Python - convert list of tuples to string

后端 未结 7 1450
执笔经年
执笔经年 2020-12-05 10:50

Which is the most pythonic way to convert a list of tuples to string?

I have:

[(1,2), (3,4)]

and I want:

\"(1,2), (         


        
相关标签:
7条回答
  • 2020-12-05 11:31

    Three more :)

    l = [(1,2), (3,4)]
    
    unicode(l)[1:-1]
    # u'(1, 2), (3, 4)'
    
    ("%s, "*len(l) % tuple(l))[:-2]
    # '(1, 2), (3, 4)'
    
    ", ".join(["%s"]*len(l)) % tuple(l)
    # '(1, 2), (3, 4)'
    
    0 讨论(0)
提交回复
热议问题