Last active
May 15, 2016 04:24
-
-
Save Lvl4Sword/d7f7092de0a2c3a8cf473f6ffdd3fd41 to your computer and use it in GitHub Desktop.
Comparing two strings
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
# 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