-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs_findEmailDomain.py
32 lines (20 loc) · 1.01 KB
/
cs_findEmailDomain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# An email address such as "[email protected]" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com").
# The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses.
# Given a valid email address, find its domain part.
# Example
# For address = "[email protected]", the output should be
# solution(address) = "example.com";
# For address = "[email protected]", the output should be
# solution(address) = "codesignal.com".
def solution(address):
target_index= []
for s in range(len(address)):
if address[s]=="@":
target_index.append(s)
if len(target_index)==1:
return address[target_index[0]+1:]
else:
return address[target_index[-1]+1:]
def solution(address):
a = address.split('@')
return a[-1]