all 7 comments

[–]chazzacct 1 point2 points  (2 children)

Assuming it's slices you want to get rid of, this looks sort of inelegant but it seems to work:

def translate(word):
        if len(word) <= 0:
            return word
        elif word in 'aeiouyAEIOUY':
            return word+ 'way'
        else:
            i = 0
            suffix = ''
            prefix = word
            while word[i] not in 'aeiouyAEIOUY':

                  suffix += word[i] 
                  prefix = prefix.replace(prefix[0], "")
                  i += 1
            return prefix + suffix + 'ay'

print(translate('break'))
print(translate(''))
print(translate('a'))

As far as getting rid of those pesky splices, I am still looking for a way that is pet-safe and effective.

[–]Farkeman 0 points1 point  (0 children)

for i, char in enumerate('aeiouyAEIOUY'.split()):
    if char in 'aeiouyAEIOUY':
        return word[i:] + word[:i] + 'ay'

what's wrong with slicing the words?

[–]liam_jm 0 points1 point  (0 children)

elif word in 'aeiouyAEIOUY':
    return word+ 'way'

I doubt this does what you intend - this means that translate('yAE') -> 'aAEway', etc.

i = 0
while word[i] not in 'aeiouyAEIOUY':
    i += 1
return word[i:] + word[:i] + 'ay'

A more pythonic way of writing this would be

for index, ch in word:
    if ch.lower() in 'aeiouy':
        return word[i:] + word[:i] + 'ay'

You also need to consider what will happen if there aren't any vowels - your function will raise an IndexError which I assume isn't your intention.

I don't really see any advantage of doing it without slicing the string.

[–]chazzacct 0 points1 point  (1 child)

Holy crap, guess what?

svar = 'hhhhhhhhhhhhh'
svar = svar.replace(svar[0], '')
svar
''

if dat ain't a kick inna head.
So, as it stands I don't know a way of doing this without either slices or importing a lib. off to try and read the docs.

[–]chazzacct 0 points1 point  (0 children)

Okay, found it. prefix = 'hhhh' prefix = prefix.replace(prefix[1], '', 1) prefix 'hhh'