"ab & ac" が英数字ではなく(& と空白のため)、タイプミスをしたと仮定すると、これでうまくいきます。
def removeNonAlpha(i,j):
indexI = 0
indexJ = 0
while indexJ < len(j):
if not j[indexJ].isalnum():
j[indexJ] = i[indexI]
indexI += 1
indexJ += 1
return j
>>>i=["a","b", "c"]
>>>j=["abc","(3)","ab & ac", "(1,4)","xyz"]
>>>removeNonAlpha(i,j)
['abc', 'a', 'b', 'c', 'xyz']
このコードは、j を完全に置き換えるのに十分な要素が i にあることも前提としています。
特別な理由で&記号を許可する必要がある場合 (これは、空白も許可する必要があることを意味します)、代替手段は次のとおりです。
def removeNonAlpha(i,j):
indexI = 0
indexJ = 0
while indexJ < len(j):
if not j[indexJ].replace('&', '').replace(' ', '').isalnum():
j[indexJ] = i[indexI]
indexI += 1
indexJ += 1
return j
>>>i=["a","b"]
>>>j=["abc","(3)","ab & ac", "(1,4)","xyz"]
>>>removeNonAlpha(i,j)
['abc', 'a', 'ab & ac', 'b', 'xyz']