【问题标题】:Getting the same result as the print [duplicate]获得与打印相同的结果[重复]
【发布时间】:2020-09-04 11:31:40
【问题描述】:
def dot_trick(username):
    emails = list()
    username_length = len(username)
    combinations = pow(2, username_length - 1)
    padding = "{0:0" + str(username_length - 1) + "b}"
    for i in range(0, combinations):
        bin = padding.format(i)
        full_email = ""

        for j in range(0, username_length - 1):
            full_email += (username[j]);
            if bin[j] == "1":
                full_email += "."
        full_email += (username[j + 1])
        emails.append(full_email + "mars")
    return emails

username = ("marsbros")
print(*dot_trick(username) , sep="\n")

我想得到与printsep='\n' 相同的结果,并将其逐行写入文件。

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    你可以试试这个

    def dot_trick(username):
        emails = list()
        username_length = len(username)
        combinations = pow(2, username_length - 1)
        padding = "{0:0" + str(username_length - 1) + "b}"
        for i in range(0, combinations):
            bin = padding.format(i)
            full_email = ""
    
            for j in range(0, username_length - 1):
                full_email += (username[j]);
                if bin[j] == "1":
                    full_email += "."
            full_email += (username[j + 1])
            emails.append(full_email + "mars")
        return emails
    
    username = ("marsbros")
    print(*dot_trick(username) , sep="\n",file=open("username.txt", "a"))
    print(*dot_trick(username) , sep="\n")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多