need to count distinct gmail addresses provided by user as input, here are the conditions:
not case sensitive:
"a@gmail.com" == "A@GmaiL.com"
The '.' character in the string in the local name is ignored:
"aa@gmail.com" == "a.a@gmail.com"
Gmail domain is same as googlemail
"aa@gmail.com" == "aa@googlemail.com"
my issue is with the very last one. How to implement the last condition in my code?
distinct_emails=[]
email = []
count=0
for i in range(int(input())):
item = input().lower().replace(".","")
email.append(item)
for i in email:
if i not in distinct_emails:
count = count + 1
distinct_emails.append(i)
print(count)
You could try something like this, where for gmail and googlemail addresses, you check for the swapped versions before appending it to the distinct_emails
list.
distinct_emails=[]
email = []
count=0
for i in range(int(input())):
item = e.lower()
# don't remove `.` after the `@`.
parts = item.split("@")
email.append(parts[0].replace(".", "") + "@" + parts[1])
for i in email:
# consider googlemail and gmail to be equivalent
if not any(e in distinct_emails for e in [i, i.replace('@googlemail.com', '@gmail.com'), i.replace('@gmail.com', '@googlemail.com')]):
count = count + 1
distinct_emails.append(i)
print(count)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.