Ho una tupla di caratteri come questa:
('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
Come faccio a convertirla in una stringa in modo che sia come:
'abcdgxre'
Usa str.join
:
>>> tup = ('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
>>> ''.join(tup)
'abcdgxre'
>>>
>>> help(str.join)
Help on method_descriptor:
join(...)
S.join(iterable) -> str
Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S.
>>>
Questo funziona:
''.join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))
Produrrà:
'abcdgxre'
Puoi anche usare un delimitatore come una virgola per produrre:
'a,b,c,d,g,x,r,e'
Usando:
','.join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))