Skip to content

Instantly share code, notes, and snippets.

@Lvl4Sword
Last active May 15, 2016 04:24
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 Lvl4Sword/d7f7092de0a2c3a8cf473f6ffdd3fd41 to your computer and use it in GitHub Desktop.
Save Lvl4Sword/d7f7092de0a2c3a8cf473f6ffdd3fd41 to your computer and use it in GitHub Desktop.
Comparing two strings
# Even spaces are compared!
my_string1 = "h4110 w0r1d"
my_string2 = "hello world"
def similar(my_string1, my_string2):
a = b = c = d = []
a.append(my_string1)
b.append(my_string2)
counter = 0
try:
for each in my_string1:
if each.lower() == b[0][counter].lower():
c.append(each)
else:
d.append(each)
counter += 1
except AttributeError:
pass
except IndexError:
pass
similar = len(c)
starting = len(a)
total = similar / starting
print("There were {0} out of {1} similar characters.".format(int(total), len(my_string1)))
if d:
print("The following characters were not found in the second string:")
print('"{0}"'.format(', '.join(d)))
similar(my_string1, my_string2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment