python - Converting a list of integers to a string -


i have list in following manner:

foo=[21, 38, 38, 56, 23, 19, 11, 15, 19, 13, 20, 6, 0, 8, 0, 10, 11, 0, 11, 8, 12, 5] 

and want convert like:

bar=21, 38, 38, 56, 23, 19, 11, 15, 19, 13, 20, 6, 0, 8, 0, 10, 11, 0, 11, 8, 12, 5 

how should done? tried bar=''.join(foo) gives me error message.

you're looking for:

''.join(map(str, foo)) 

this maps each integer through str, can joined together. though, may want add comma between them:

', '.join(map(str, foo)) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -