How would I find all occurances of the letter 'e' for example in a list of the split word elephant?
I've tried using letterlist.index('e') for example but index only returns the first occurance of e.

This is to be used in a hangman game, and the game needs to display all the characters that have been guessed amongst a list of "-" dashes
So how would I replace "-" with the correctly guessed letter.

Thanks!

print(['e' if letter == 'e' else '-' for letter in 'elephant'])
'''Output:
['e', '-', 'e', '-', '-', '-', '-', '-']
'''

Your code is not tested to work and does not belong to code snippets.

So how would I replace "-" with the correctly guessed letter

There are 3 containers here, the "secret word", the hangman list, and the letter quessed. You would iterate over the "secret word" and compare letters. If the letters match then replace the "-" at the same postion in the hangman list..

for position in range(len(secret_word)):
    letter = secret_word[position]
Be a part of the DaniWeb community

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