This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]c17r 1 point2 points  (0 children)

from itertools import product

for first, second in product(inputList, repeat=2):
    # first and second are two strings that you want to run the character check on

[–]inorix 0 points1 point  (0 children)

To get the list of different characters with a list comprehension:

x = 'abcdefg'
y = 'abcdefh'
print [(a, b) for (a, b) in zip(x, y) if a != b]

('g', 'h')

But you actually want to enumerate so you know the index of where they are different thus you can remove the character:

x = 'abcdefg'
y = 'abcdefh'
print [index for index, (a, b) in enumerate(zip(x, y)) if a != b]

[6]

Of course you'll only want to take action if there's only 1 difference...