Python - Print items in list with neither commas nor apostrophes

后端 未结 2 1894
萌比男神i
萌比男神i 2021-01-25 14:30

Minimal working example of my code:

# Create output data file
out_data_file = open(\'output_file\',\'w\')
out_data_file.write(\"# Header \\n\")
out_data_file.clo         


        
2条回答
  •  清酒与你
    2021-01-25 15:06

    Use
    
    In [10]: list1 = [1,3,4,5,12,6,2,35,74,6,2]
    
    In [11]: " ".join(map(str, list1))
    Out[11]: '1 3 4 5 12 6 2 35 74 6 2'
    

    ...or in your case:

    f.write('Text' + ' ' + " ".join(map(str, list1)))
    

提交回复
热议问题