I need to merge strings together to create one string. For example the strings for "hello" that need to be combined are:
[H----], [-E---], [--LL-], and [----O]
This is the current code I have to make the letters appear in the first place.
display_string = "[" + "".join([x if x == letter else "-" for x in word]) + "]"
How would I go about making strings such as
[H----], [HE---], [HELL-], and finally [HELLO]?
I don't know whether this helps in the way you wanted, but this works. The problem is that we don't really have a string replacement. A list of chars might work better for you until the final assembly.
string_list = ['H----','-E---','--LL-','----O'
]word_len = len(string_list[0])
display_string = word_len*'-'
for word in string_list:for i in range(word_len):if word[i].isalpha():display_string = display_string[:i] + word[i] + display_string[i+1:]print '[' + display_string + ']'