Last active
December 23, 2020 18:42
-
-
Save elkym/69ec17d1ffce63a5833984e0a42341aa to your computer and use it in GitHub Desktop.
Python string comparator from csv input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
words = [] | |
def charComp(a, b): | |
if a == b: | |
return ("100%") | |
tempW = '' | |
for count in range(len(a)): | |
if count >= len(a) or count >= len(b): | |
v1 = round(len(tempW) / len(a) * 100) | |
v2 = round(len(tempW) / len(b) * 100) | |
return (str(v1) + "%", str(v2) + "%") | |
if a[count] != b[count]: | |
v1 = round(len(tempW) / len(a) * 100) | |
v2 = round(len(tempW) / len(b) * 100) | |
return (str(v1) + "%", str(v2) + "%") | |
else: | |
tempW = tempW + a[count] | |
def readNamesFile(): | |
with open("./Test function.csv") as namescsv: | |
csv_reader = csv.reader(namescsv, delimiter=',') | |
for row in csv_reader: | |
a = ' '.join(row[0].split()) | |
b = ' '.join(row[1].split()) | |
if len(a) >= len(b): | |
words.append(charComp(a,b)) | |
else: | |
x = list(charComp(b,a)) | |
x.reverse() | |
x = tuple(x) | |
words.append(x) | |
readNamesFile() | |
for line in words: | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment