Skip to content

Instantly share code, notes, and snippets.

@elkym
Last active December 23, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elkym/69ec17d1ffce63a5833984e0a42341aa to your computer and use it in GitHub Desktop.
Save elkym/69ec17d1ffce63a5833984e0a42341aa to your computer and use it in GitHub Desktop.
Python string comparator from csv input
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