-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSeqmatch.py
32 lines (26 loc) · 1.05 KB
/
Seqmatch.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
from difflib import SequenceMatcher
def similarity(sing, itr):
queue = {}
a, b, c = itr
compareA = SequenceMatcher(None, sing, a).ratio()
compareB = SequenceMatcher(None, sing, b).ratio()
compareC = SequenceMatcher(None, sing, c).ratio()
queue[a] = compareA
queue[b] = compareB
queue[c] = compareC
return max(queue, key=queue.get)
def apostrophe_checker(inpList):
inpList = list(inpList)
for q in inpList:
if "'" in q:
apostrophe_index = inpList.index(q)
AposSliced = slice(apostrophe_index, (apostrophe_index + 2))
tText = inpList[AposSliced]
# Apos Word is the word found and concatenated with apostrophe in it.
AposWord = "".join(inpList[AposSliced])
# New List is the original list with the apostrophe word left out
newList = [q for q in inpList if q not in tText]
newList.insert(apostrophe_index, AposWord)
# replace the working list with the new one
inpList = newList
return inpList