Validating and Parsing Email Addresses in Python HackerRank Solution

Hello coders, In this post, you will learn how to solve Validating and Parsing Email Addresses in Python HackerRank Solution. This problem is a part of the Python Hacker Rank series.

We also provide Hackerrank solutions in CC++Java programming, and Python Programming languages so whatever your domain we will give you an answer in your field.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

Validating and Parsing Email Addresses in Python HackerRank Solution
Validating and Parsing Email Addresses in Python HackerRank Solution

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology, Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

Validating and Parsing Email Addresses in Python HackerRank Solution

problem

A valid email address meets the following criteria:

  • It’s composed of a username, domain name, and extension assembled in this format: [email protected]
  • The username starts with an English alphabetical character, and any subsequent characters consist of one or more of the following: alphanumeric characters, -,., and _.
  • The domain and extension contain only English alphabetical characters.
  • The extension is 1, 2, or 3 characters in length.

Given n pairs of names and email addresses as input, print each name and email address pair having a valid email address on a new line.
Hint : Try using Email.utils() to complete this challenge. For example, this code:

import email.utils
print email.utils.parseaddr('DOSHI <[email protected]>')
print email.utils.formataddr(('DOSHI', '[email protected]'))

produces this output:

('DOSHI', '[email protected]')
DOSHI <DOSHI@hackerrank.com>

Input Format :

The first line contains a single integer, n, denoting the number of email address.
Each line i of the n subsequent lines contains a name and an email address as two space-separated values following this format:

name <user@email.com>

Constraints :

  • 0 < N < 100

Output Format :

Print the space-separated name and email address pairs containing valid email addresses only. Each pair must be printed on a new line in the following format:

name <user@email.com>

You must print each valid email address in the same order as it was received as input.


Sample Input :

2
DEXTER <dexter@hotmail.com>
VIRUS <virus!@variable.:p>

Sample Output :

DEXTER <dexter@hotmail.com>

Explanation :

[email protected] is a valid email address, so we print the name and email address pair received as input on a new line.
[email protected]:p is not a valid email address because the username contains an exclamation point (!) and the extension contains a colon (:). As this email is not valid, we print nothing.



Validating and Parsing Email Addresses in Python HackerRank Solution

import re
N = int(input())
for i in range(N):
    name, email = input().split()
    pattern="<[a-z][a-zA-Z0-9\-\.\_][email protected][a-zA-Z]+\.[a-zA-Z]{1,3}>"
    if bool(re.match(pattern, email)):
        print(name,email)

Disclaimer: The above Problem (Validating and Parsing Email Addresses in Python – HackerRank Solution) is generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

FAQ:

Does HackerRank have Python?

HackerRank’s programming challenges can be solved in a variety of programming languages (including Java, C++, PHP, Python, SQL, JavaScript) and span multiple computer science domains.

Where can I practice Python coding?

  • HackerRank is a great site for practice that’s also interactive.

Where can I find HackerRank solutions in Python?

in this post, you will get all the solutions to HackerRank Python Problems.

Is possible HackerRank Solution in Python?

HackerRank’s programming challenges can be solved in a variety of programming languages (including Java, C++, PHP, Python, SQL, and JavaScript) and span multiple computer science domains. When a programmer submits a solution to a programming challenge, their submission is scored on the accuracy of their output.

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe.

Sharing Is Caring

Leave a Comment