buly
buly

Reputation: 103

Convert list to string

I have this list:

scores = [
    ('WillyCaballero', '2'),
    ('Angeleri', '2'),
    ('Antunes', '2'),
    ('FlavioFerreira', '2'),
    ('Camacho', '2'),
    ('SamuGarc\xc3\xada', '2'),
    ('I\xc3\xb1igoMart\xc3\xadnez', '2'),
    ('Jos\xc3\xa9\xc3\x81ngel', '6')
    ...
]

How to store in one str variable and output like this format?:

Willy Caballero 2   
Angeleri 2  
Antunes 2  
...

Upvotes: 3

Views: 98

Answers (5)

pythonian29033
pythonian29033

Reputation: 5207

I would do this;

scoresList = ''
for score in scores:
   scoresList += ' '.join(score) + '\n'
#end loop

Upvotes: 0

Prashant Gaur
Prashant Gaur

Reputation: 9828

Edited

>>> out = map(' '.join, p)
>>> for i in out:
...     print i
... 
WillyCaballero 2
Angeleri 2
Antunes 2
>>> 

Upvotes: 0

New_User123
New_User123

Reputation: 104

for i in scores:
    print i[0],i[1]

Upvotes: 0

BlackMamba
BlackMamba

Reputation: 10252

str = '\n'.join(' '.join(s) for s in scores)
print(str)

Upvotes: 0

zhangxaochen
zhangxaochen

Reputation: 34047

Using str.join, join elements with whitespace first and then with '\n'

In [25]: print '\n'.join(' '.join(s) for s in scores)
Willy Caballero 2
Angeleri 2
Antunes 2
Flavio Ferreira 2
...

Upvotes: 6

Related Questions