-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
82 lines (75 loc) · 2.2 KB
/
util.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# sort the array
def sort(words):
sorted_words = sorted(words)
return sorted_words
# write array to file
def writeToFile(arr):
from datetime import datetime
filename = datetime.now().strftime("%H:%M:%S")
with open(filename+'.txt', 'w') as output_file:
for a in arr:
output_file.write(a+'\n')
print('File created: '+ filename)
# Read words from input file and create the array full of those
def readFromTXTFileAndGenerateArray(filename):
arr = []
with open(filename ,'r') as file:
words = file.read().splitlines()
for word in words:
arr.append(word)
return arr
# Remove duplicates from array
def removeDuplicatesInArray(arr):
return list(set(arr))
# Get the different letter count of 2 words
def getDiffCountOfTwoWords(str1, str2):
diff_count = 0
if abs(len(str1) - len(str2))>1:
diff_count = abs(len(str1) - len(str2))
if len(str1) == len(str2):
for i in range(len(str1)):
if str1[i] != str2[i]:
diff_count +=1
elif abs(len(str1) - len(str2))==1:
if len(str1)>len(str2):
max = str1
min = str2
else:
max = str2
min = str1
for i in range(len(max)):
if i == len(max):
diff_count = 1
if max[i] == min[i]:
continue
else:
if max[i] != min[i]:
max_v2 = max[0:i]+max[i+1:len(max)]
if min == max_v2:
diff_count = 1
else:
diff_count = 2
return diff_count
return diff_count
# Check the elements in the array
def checkElementsInArray(arr):
arr2 = []
for a in arr:
if len(a)<4:
print('ERROR. Too short:', a)
if a in arr2:
print('ERROR. Duplicate:', a)
else:
for a2 in arr2:
if a[0:4] == a2[0:4]:
print('ERROR. Words have the same first 4 letters:', a, a2)
else:
if getDiffCountOfTwoWords(a,a2)<2:
print('ERROR. Words are similar:', a, a2)
arr2.append(a)
for c in a:
if c.isupper():
print('ERROR. Contains capital letter:', a)
break
if 'â' in a or 'ı' in a or 'ğ' in a or 'ü' in a or 'ş' in a or ' ' in a or 'ö' in a or 'ç' in a or ':' in a or '_' in a:
print('ERROR. Contains a non-english letter or a sign:', a)