Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python | ||
import time | ||
import itertools | ||
|
||
__author__ = 'ty' | ||
|
||
|
||
INPUT = "The quick brown fox jumps over the lazy dog" | ||
|
||
print "Please enter '"+INPUT+"': \n" | ||
|
||
var = "" | ||
|
||
|
||
def compare(string1, string2, no_match_c=' ', match_c='|'): | ||
|
||
result_c = '' | ||
diff_count = 0 | ||
|
||
if len(string2) < len(string1): | ||
string1, string2 = string2, string1 | ||
|
||
for c1, c2 in itertools.izip(string1, string2): | ||
if c1 == c2: | ||
result_c += match_c | ||
else: | ||
result_c += no_match_c | ||
diff_count += 1 | ||
delta = len(string2) - len(string1) | ||
result_c += delta * no_match_c | ||
diff_count += delta | ||
return result_c, diff_count | ||
|
||
while var != "exit": | ||
try: | ||
before = time.time() | ||
var = raw_input() | ||
after = time.time() | ||
time_user_input = after-before | ||
if var == "exit": | ||
print "bye" | ||
else: | ||
result, n_diff = compare(INPUT, var, no_match_c='*') | ||
print result | ||
print INPUT | ||
print "used", time_user_input, "seconds,", "%d difference(s)." % n_diff, "\n" | ||
except EOFError: | ||
print "bye" | ||
var = "exit" |