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

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

    data =         


        
9条回答
  •  庸人自扰
    2020-12-31 09:53

    In the previously reply, I have made a wrong answer because I have misunderstood the requirements, please ignore it.

    I think you can use join to simplify the inner loop

    data = open("list.txt", "w")
    for c in s_chars:
        data.write("%s%s\n" % (c, c.join(nums)))
    data.close()
    

提交回复
热议问题