Is there an easy way to find minimal pairs with python given a list of words? A minimal pair is a pair of two words that differ only in one sound (one character in pythonian terms). So for example in a list like:
wordlist = ["paka", "baka", "puki", "paki", "suki", "suku"]
minimal pairs would be: "paka" and "baka", "puki" and "paki", "puki" and "suki", "suki" and "suku"
I am new to python, I tried to search for a suitable function that can match characters except one in comparing two strings but I haven't find something useful.
A simple solution : you iterate through your list with word1 and compare with all the others words (word2). You count the differences at each position. The following example will probably work for your task...
wordlist = ["paka", "baka", "puki", "paki", "suki", "suku", "buku","baba","nabab"]
for n1,word1 in enumerate(wordlist):
for word2 in wordlist[n1+1:]:
if len(word1)==len(word2):
ndiff=0
for n,letter in enumerate(word1):
if word2[n]!=letter:
ndiff+=1
if ndiff==1:
print word1, word2