Right now I'm trying to create an oppish translator. That is, after a consonant or several consonants in a row, you add 'op' to those letters. As an example, cow would become copowop or street which would become stropeetop. This is what I have so far:

def oppish(phrase): #with this function I'm going to append 'op' or 'Op' to a string.
    consonants =  ['b','c','d','f','g','h','i','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
    vowels = ['a', 'e', 'i', 'o', 'u'] #this and the preceding line create a variable for the vowels we will be looking to append 'op' to.    
    if phrase == '':    #error case. if the input is nothing then the program will return False.
        return False
    phrase_List = list(' ' + phrase) # turns the input phrase into a list which allows for an        index to search for consonants later on.
    new_phrase_List = list() #creates new list for oppish translation
    for i in range(1, len(phrase_List)):
        if phrase_List[i] == phrase_List[1]:
        elif phrase_List[i] in consonants:
            new_phrase_List.append('op') #adds op to the end of a consonant within the list and then appends it to the newlist
        new_phrase_List.append(phrase_List[i]) #if the indexed letter is not a consonant it is appended to the new_phrase_list.
    print 'Translation: ' + ''.join(new_phrase_List)


The only problem here is that the above code yields this

Translation: ssoptopreeopt
I'm not sure what I've done wrong, I've tried going through a visualizer but to no avail. All help is appreciated! :)

Think about where you are going to insert op if the phrase is street. You are going to insert op when you meet the first e, because it is not a consonant and the previous letter is a consonant. You are also going to insert op at the end of the string because the previous letter is a consonnant. So, an algorithm would go this way, in pseudo-code.

previous_is_a_consonant = False
for letter in phrase:
    if letter is a consonant:
        previous_is_a_consonant = True
        if previous_is_a_consonant:
            append 'op'
        previous_is_a_consonant = False
    append letter
if previous_is_a_consonant:
    append 'op'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.