I have a list of words i.e. [‘cat’, ‘dog’, ‘chicken’] and I want to replace all letters except the first with an underscore. I tried using for loops but I couldn’t get it to work.
Advertisement
Answer
JavaScript
x
7
1
x = ['cat', 'dog', 'chicken']
2
3
y = [word[0] + '_'*(len(word)-1) for word in x]
4
5
print(y)
6
# ['c__', 'd__', 'c______']
7