How to write list of strings to file, adding newlines?

前端 未结 9 1385
借酒劲吻你
借酒劲吻你 2020-12-31 09:02
def generator():
    nums = [\'09\', \'98\', \'87\', \'76\', \'65\', \'54\', \'43\']
    s_chars = [\'*\', \'&\', \'^\', \'%\', \'$\', \'#\', \'@\',]

    data =         


        
9条回答
  •  攒了一身酷
    2020-12-31 09:45

    def generator():
         nums = ['09', '98', '87', '76', '65', '54', '43']
         s_chars = ['*', '&', '^', '%', '$', '#', '@',]
    
         data = open("list.txt", "w")
         for c in s_chars:
            for n in nums:
               data.write(c + n + "\n")
         data.close()
    

    OR

    def generator():
         nums = ['09', '98', '87', '76', '65', '54', '43']
         s_chars = ['*', '&', '^', '%', '$', '#', '@',]
    
         data = open("list.txt", "w")
         for c in s_chars:
            for n in nums:
               data.write(c + n)
            data.write("\n")
         data.close()
    

    depending on what you want.

提交回复
热议问题