Hee Ra Choi
Hee Ra Choi

Reputation: 113

How can I make these names into email form?

I need to put these names into email form.

For example, I have these names list:

saint christopher
lebron james
kevin durant
kyrie andrew irving
d j khaled
bloodpop(r)

And need to get the result of:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

I have made them into lower case and try to use split() but doesn't work.

I have done:

fname = input("Enter filename:")
infile = open(fname, "r")

for line in infile:
    first,last = line.lower().split()
    uname = (first[0] + last[:8])
    print(uname)
infile.close()

I get an error that says:

  first,last = line.lower().split()
ValueError: too many values to unpack (expected 2)

Upvotes: 0

Views: 64

Answers (2)

Adam Smith
Adam Smith

Reputation: 54223

You can use splat tuple assignment to split the firsts away from the last, grab the first initials of each of the firsts, then join them with the last and slice off the first 8 characters.

def make_username(name, suffix="gmail.com"):
    *firsts, last = name.lower().split()
    initials = ''.join([s[0] for s in firsts])
    username = ''.join([initials, last])[:8]
    return f"{username}@{suffix}"

Upvotes: 2

PravinSanghani
PravinSanghani

Reputation: 129

Try this..

email_name = 'saint christopher'

import string

new_str = string.replace(email_name,' ', '')
print(new_str)

it gives you out put: saintchristopher

Upvotes: -1

Related Questions