'Python exercise for 'remove suffix ness from the string/s'

I am trying to solve the python exercise for 'remove suffix ness from the string' and have written the following code, but I am unable to pass the test

def remove_suffix_ness(word):
    no_suffix = [word[:-4] for word in word]
    for i in range(len(no_suffix)):
        if no_suffix[i][-1] == 'i':
        no_suffix[i] = no_suffix[i][:-1] + 'y'
    else:
        pass
    return ', '.join(no_suffix)

The code is supposed to take the following as Input:

Input = ['heaviness', 'sadness', 'softness', 'crabbiness', 'lightness', 'artiness', 'edginess']

and Output should be a string without ness and if the string is ending with 'i' I have to replace 'i' with 'y'. It should look something like this:

Output = heavy, sad, soft, crabby, light, arty, edgy

I am getting the following message:

TEST FAILURE
    IndexError: string index out of range


Solution 1:[1]

I think the problem is your test doesn't pass a list of strings to your method, but only a single word each time.

Can you try to return the solution for a single word?

def remove_suffix_ness(word):
   return word[:-5] + 'y' if word.endswith('iness') else word[:-4]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Christian Weiss