-3
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")

I want to get the same result as print with sep='\n' and write it to a file line by line.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Mars Bros
  • 1
  • 7

1 Answers1

0

you can try this

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")
Janith
  • 403
  • 6
  • 14