forked from jamil-said/code-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomainType.py
More file actions
executable file
·50 lines (35 loc) · 1.59 KB
/
domainType.py
File metadata and controls
executable file
·50 lines (35 loc) · 1.59 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
""" domainType -- 5 min
GoDaddy makes a lot of different top-level domains available to its customers.
A top-level domain is one that goes directly after the last dot ('.') in
the domain name, for example .com in example.com. To help the users choose
from available domains, GoDaddy is introducing a new feature that shows the
type of the chosen top-level domain. You have to implement this feature.
To begin with, you want to write a function that labels the domains as
"commercial", "organization", "network" or "information" for .com, .org,
.net or .info respectively.
For the given list of domains return the list of their labels.
Example
For domains = ["en.wiki.org", "codesignal.com", "happy.net", "code.info"],
the output should be
domainType(domains) = ["organization", "commercial", "network", "information"].
Input/Output
[execution time limit] 4 seconds (py3)
[input] array.string domains
A list of domains, where each domain contains at least one dot. It is
guaranteed that each top-level domain of these domains belongs to one of
the types described above.
Guaranteed constraints:
4 ≤ domains.length ≤ 25,
5 ≤ domains[i].length ≤ 20.
[output] array.string
The list of labels for the given domains.
"""
def domainType(domains):
dicLabel = {'org': 'organization', 'com': 'commercial', 'net': 'network'
, 'info': 'information'}
result = []
for d in domains:
result.append(dicLabel[d.rsplit('.',1)[1]])
return result
print(domainType(["en.wiki.org", "codesignal.com", "happy.net", "code.info"]))
# ["organization", "commercial", "network", "information"]