Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list in this format,

['com', 'kill', 'someone', 'get', 'caught']

And i need this to be written on to a text file as,

com kill someone get caught

Basically i need spaces between words.

What I have tried:

However, i have tried methods such as,

1)
for t in some_list:
  f.write(' '.join(str(s) for s in t) + '\n')

2)
" ".join(map(str, f))


Where f is the list

Non of the above seem to work to get my outcome. Any help?
Posted
Updated 26-Jul-17 16:03pm

1 solution

you dont need the for loop at all
try this
some_list = ['com', 'kill', 'someone', 'get', 'caught']
f.write(' '.join(str(s) for s in some_list))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900