-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain-hits.py
61 lines (47 loc) · 1.45 KB
/
domain-hits.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import Union, List
'''
for a set of elements in an array with the shape [10, "google.com"]
being the first element the number of hit for the second the domain
get any sub domain in a given list of domains and the number of the
specific subdomain hist, order does not matter:
result:
[
[10, "jsfiddle.com"],
[20, "maps.google.com"],
[30, "photos.google.com"],
[50, "google.com"],
[60, "com"],
]
'''
Domain = List[Union[int, str]]
Result = dict[str, int]
data: List[Domain] = [
[10, "jsfiddle.com"],
[20, "maps.google.com"],
[30, "photos.google.com"]
]
def getDicFromList(input: List[Domain]) -> Result:
return { key: value for [value, key] in input }
def getSubDomainsRecursively(input: list[str], acc: Result, ref: Result) -> Result:
domainName = '.'.join(input)
result = acc.copy()
domain = result.get(domainName)
if(len(input) == 0):
return result
if(domain is None):
domain = 0
for k, v in ref.items():
if (domainName in k):
domain = domain + v
result[domainName] = domain
input.pop(0)
return getSubDomainsRecursively(input, result, ref)
return result
def main():
obj = getDicFromList(data)
result: Result;
for k in obj.items():
subDomains = k.split('.')
result = getSubDomainsRecursively(subDomains[1:len(subDomains)], obj, obj)
print([[v,k] for k,v in result.items()])
main()