-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckprefix.py
More file actions
51 lines (41 loc) · 1.56 KB
/
checkprefix.py
File metadata and controls
51 lines (41 loc) · 1.56 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
48
49
50
51
def addOne(foundPrefix, prefix, name, price):
prefixList = foundPrefix.setdefault((name, price), [])
prefixList.append(prefix)
def addAll(priceList):
foundPrefix = {}
for price in priceList:
addOne(foundPrefix, price[0], price[1], price[2])
return foundPrefix
def checkPrefix(prefixList):
differentPrefixMap = {}
for prefix in prefixList:
prefixPattern = str(prefix)[:-1]
lastPrefixDigit = int(str(prefix)[-1])
differentPrefixMap.setdefault(prefixPattern, set()).update((lastPrefixDigit,))
for prefix, lastDigitSet in differentPrefixMap.items():
if len(lastDigitSet) == 10:
return True
return False
def check(priceList):
foundPrefix = addAll(priceList)
wrongPrefix = []
for key, prefixList in foundPrefix.items():
# Optimization: if less then 10 prefix was found there are no all last 0-9 digits
if len(prefixList) >= 10:
if checkPrefix(prefixList):
wrongPrefix.append(key)
return wrongPrefix
if __name__ == '__main__':
prefixList = [
('37060', 'Country test name', '0.5'),
('37167', 'Country test name', '0.5'),
('37061', 'Country test name', '0.5'),
('37062', 'Country test name', '0.5'),
('37063', 'Country test name', '0.5'),
('37064', 'Country test name', '0.5'),
('37065', 'Country test name', '0.5'),
('37066', 'Country test name', '0.5'),
('37068', 'Country test name', '0.5'),
('37069', 'Country test name', '0.5'),
]
print check(prefixList)