Given an array of strings possible_emails, how many unique emails does it contain? You can assume that all strings you will receive will be a valid email, as defined above.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def solution (input):
valid_emails. =
for i in input:
set()
i = i.lowercase()
name, domain i.split('@')
currVal = name.split('+')[0].replace('.
valid_emails.add(currVal + '@' + domain)
return len(valid_emails)
A user is trying to make a new Twitch account with their email. But Twitch has a problem with
"bots": users that make spam accounts on Twitch under fake emails. In this problem, given a user
who tries to make an account with a certain number of emails, we want to determine how many of
them are unique.
Valid emails consist of a username and a domain. They are separated by the '@' sign. The emails
abide by certain rules:
• Emails are case insensitive. This means that ninja@twitch.tv is the same email as
Ninja@twitch.tv and ninja@Twitch.tv.
• In addition to letters and numbers, the email may contain one or more '.' or '+'.
• If you add periods '.' between some characters in the username, this is equivalent to the same
address without dots in the username. Note that this rule does not apply to domain names.
Example: ninja@twitch.tv is the same email as nin.ja@twitch.tv, but ninja@twitch.tv is not the
same as ninja@twi.tch.tv.
If you add a plus '+' in the username, every character following it in the username will be
ignored. Note that this rule again does not apply to domain names. Example:
ninja+1@twitch.tv is the same email as ninja+2@twitch.tv, but ninja@twitch.tv is not the same
as ninja@tw+tch.tv.
• All of these rules can be used at the same time.
Given an array of strings possible_emails, how many unique emails does it contain? You can
assume that all strings you will receive will be a valid email, as defined above.
Transcribed Image Text:main.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def solution (input): valid_emails. = for i in input: set() i = i.lowercase() name, domain i.split('@') currVal = name.split('+')[0].replace('. valid_emails.add(currVal + '@' + domain) return len(valid_emails) A user is trying to make a new Twitch account with their email. But Twitch has a problem with "bots": users that make spam accounts on Twitch under fake emails. In this problem, given a user who tries to make an account with a certain number of emails, we want to determine how many of them are unique. Valid emails consist of a username and a domain. They are separated by the '@' sign. The emails abide by certain rules: • Emails are case insensitive. This means that ninja@twitch.tv is the same email as Ninja@twitch.tv and ninja@Twitch.tv. • In addition to letters and numbers, the email may contain one or more '.' or '+'. • If you add periods '.' between some characters in the username, this is equivalent to the same address without dots in the username. Note that this rule does not apply to domain names. Example: ninja@twitch.tv is the same email as nin.ja@twitch.tv, but ninja@twitch.tv is not the same as ninja@twi.tch.tv. If you add a plus '+' in the username, every character following it in the username will be ignored. Note that this rule again does not apply to domain names. Example: ninja+1@twitch.tv is the same email as ninja+2@twitch.tv, but ninja@twitch.tv is not the same as ninja@tw+tch.tv. • All of these rules can be used at the same time. Given an array of strings possible_emails, how many unique emails does it contain? You can assume that all strings you will receive will be a valid email, as defined above.
Failed:
Args: [["\"alexleet@code.com\"", \"alex@leetcode.com\"", \"a.lex.le
et@code.com\"." \"alex+leet@leetcode.com\""]]
Result: 3
Expected result: 2
11:11
Failed:
Args: [["\"ninja@gmail.com\
1.com\"
ail.com\""
1
11
11
11
\"nin.ja@gmail.com\"
1
Result: 3
Expected result: 1
11:11
11
NLION@lion.com\""]]
Result: 6
Expected result: 4
11
\"ninja.+streamer@gmail.com\""]]
11
\"n.inja@gmail.com\'
\"ninj.A@gmail.com\'
11
11
11 11
Passed:
Args: [["\"test.email+Alex@twitch.tv\"", "\"test.e.mail+Bob.Carol@twitc
h.tv\"", "\"testemail+David@twitch.tv\""]]
Result: 1
Failed:
Args: [["\"ninja@twitch.tv\"", \"NiNjA@TwiTch. Tv\"", \"nINJA@tWITCH
.TV\"", \"N1NJA@TWITCH.TV\"", \"NORTHERNLION@lion.com\"", \"NORTHER
Summary: 2 tests passed, 3 tests failed.
11
11
J
11
11
\"ni.nja@gmai
\"ninja.@gm
11
Passed:
Args: [["\"a@twitch.tv\"", \"b@twitch.tv\"", \"c@twitch.tv\""]]
Result: 3
11
Transcribed Image Text:Failed: Args: [["\"alexleet@code.com\"", \"alex@leetcode.com\"", \"a.lex.le et@code.com\"." \"alex+leet@leetcode.com\""]] Result: 3 Expected result: 2 11:11 Failed: Args: [["\"ninja@gmail.com\ 1.com\" ail.com\"" 1 11 11 11 \"nin.ja@gmail.com\" 1 Result: 3 Expected result: 1 11:11 11 NLION@lion.com\""]] Result: 6 Expected result: 4 11 \"ninja.+streamer@gmail.com\""]] 11 \"n.inja@gmail.com\' \"ninj.A@gmail.com\' 11 11 11 11 Passed: Args: [["\"test.email+Alex@twitch.tv\"", "\"test.e.mail+Bob.Carol@twitc h.tv\"", "\"testemail+David@twitch.tv\""]] Result: 1 Failed: Args: [["\"ninja@twitch.tv\"", \"NiNjA@TwiTch. Tv\"", \"nINJA@tWITCH .TV\"", \"N1NJA@TWITCH.TV\"", \"NORTHERNLION@lion.com\"", \"NORTHER Summary: 2 tests passed, 3 tests failed. 11 11 J 11 11 \"ni.nja@gmai \"ninja.@gm 11 Passed: Args: [["\"a@twitch.tv\"", \"b@twitch.tv\"", \"c@twitch.tv\""]] Result: 3 11
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education