如何将单个实体列表转换为字符串python

时间:2018-10-24 16:36:23

标签: python string list

我正在尝试转换一个元组:

('Cobra',)

为字符串,在打印时会产生:

Cobra

1 个答案:

答案 0 :(得分:0)

#Assuming you have a list of tuples
    sample = [('cobra',),('Cat',),('Dog',),('hello',),('Cobra',)]

#For each tuple in the list, Get the first element of each tuple
    x = [i[0] for i in sample]