i'm trying to do a Trivia program and i'm getting issues with the answers. What i want is to replace the characters of the answers to display as hints. Example:
answer = "I am just an example"
hintwouldbe = "I a_ j___ a_ e______"
hint2mightbe = "I am j___ an e_a___e"
i am not really sure how to make it. Tried with loops (for c in answer) and string.replace methods. Also tried with some re.translate and dicts but i'm getting really big codes and hard to understand. Ther must be an easer way so... here i am.
Which way do you think would be the most efficient/easier to accomplish that?
Edit It would be great if i could choose what positions to replace. for example: if the word has 6 characters, replace 1,3 and 6 characters with a _
Edit2: Right answer
After a bit change, i choose Thomas Orozco answer as valid, is quite easy to understand and re-create:
from random import random
answer = "anything in here"
pista = [char if random() < 0.8 else "_" for char in answer]
pista2 = "".join(pista)
print(pista2)