Question

In python, if i have a list of words, take example "panda", how to replace 'a'...

In python, if i have a list of words, take example "panda", how to replace 'a' with '-'?

the answer should be 'p-nd-'

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts please comment below. Please give upvote if you like this.

Python Code:

#Instalize list of words
#L = ['panda','jakas','paris'] output -> p-nd- j-k-s p-ris
L = ['panda']
#Declare empty list
res=[]
# Loop for iterate L
for string in L:
# Here w ecount the number of a's in a string
count = string.count('a')
# Here we append the result string in res list
res.append(string.replace('a','-',count))

print(*res) # Print res list

file.py - C:\Users\Vinu Bujji\Desktop\file.py (3.7.3) File Edit Format Run Options Window Help #Instalize list of words #L =

Add a comment
Know the answer?
Add Answer to:
In python, if i have a list of words, take example "panda", how to replace 'a'...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT