You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

def steps_to_convert(line1, line2):
len_line1 = len(line1)
len_line2 = len(line2)
if line1 == "" or line2 == "":
return len_line1 if len_line1 != 0 else len_line2
similarities = has_similar(line1, line2)
if len(similarities) > 0:
return abs(max(len_line1, len_line2) - len(similarities))
else:
if len_line1 < len_line2:
if line1 in line2:
return len_line2 - len_line1
else:
if line2 in line1:
return len_line1 - len_line2
return 0
def has_similar(line1, line2):
similarities = []
for index, letter in enumerate(line1):
if letter == line2[index]:
similarities.append(index)
return similarities
if __name__ == "__main__":
# These "asserts" using only for self-checking and not necessary for auto-testing
assert steps_to_convert('line1', 'line1') == 0, "eq"
assert steps_to_convert('line1', 'line2') == 1, "2"
assert steps_to_convert('line', 'line2') == 1, "none to 2"
assert steps_to_convert('ine', 'line2') == 2, "need two more"
assert steps_to_convert('line1', '1enil') == 4, "everything is opposite"
assert steps_to_convert('', '') == 0, "two empty"
assert steps_to_convert('l', '') == 1, "one side"
assert steps_to_convert('', 'l') == 1, "another side"
print("You are good to go!")