Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

count distinct gmail addresses

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading