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
  • (Python Programming)Write a Python program that prompts the user to enter a list of words and...

    (Python Programming)Write a Python program that prompts the user to enter a list of words and stores in a list only those words whose first letter occurs again within the word (for example, 'Baboon'). The program should display the resulting list.

  • IN PYTHON Write a program that, given a set of words in a list, calculate how...

    IN PYTHON Write a program that, given a set of words in a list, calculate how many words begin with the letter you capture. Entry: 5 words and 1 letter Output: # of words that have the letter. IMPORTANT NOTE: Your program should not include an input message: you are only going to capture the 5 words and finally the letter you want to find and as an output message you must indicate only the number of words that begin...

  • (PYTHON 3.8) Let's assume I have a list, in which I have two items, both of...

    (PYTHON 3.8) Let's assume I have a list, in which I have two items, both of which are list themselves(without knowing how many integers in each list, but they are the same length). For example: main_list = [[1,2,3],[4,5,6]] main_list[0] = [1,2,3] main_list[1] = [4,5,6] how can I perform operations (take addition for example) on the inner lists to their matching indexes by altering the inner lists but not removing them from main_list(temporary variables are fine) (main_list[0])[0] += (main_list[1])[0] (main_list[0])[1] +=...

  • #Python I have a dataframe: df = pd.DataFrame({'A':[0,0,15,0,0,12,0,0,0,5]}) And I want to replace the 0 value...

    #Python I have a dataframe: df = pd.DataFrame({'A':[0,0,15,0,0,12,0,0,0,5]}) And I want to replace the 0 value with the nearest non zero value, For example, the first value is 0, then I find the the nearest non-zero value is 15, so I replace it as 15, then the data becomes:[15,0,15,0,0,12,0,0,0,5], Then for all the value except first one, I need to find the both side of the nearest non-zero value, and average them. So for the second 0, it would be...

  • python code that Returns a LIST that contains ALL WORDS in word_list that have the specified...

    python code that Returns a LIST that contains ALL WORDS in word_list that have the specified length and Returns an empty list if there are no such words

  • Write a Python program to find the list of words that are longer than n from...

    Write a Python program to find the list of words that are longer than n from a given list of words and append it into a new list. Print the new list in the end. ***You have to take the list as input from the user. Sample Input: list = [“The”, “quick”, “brown”, “fox”, “jumps”, “over”, “the”, “lazy”, “dog”] n = 3 Sample Output: [“quick”, “brown”, “jumps”, “over”, “lazy”]

  • which of the following expressions should replace [4]! words[i][j] words[j][i] words[i] words[i][0] none

    which of the following expressions should replace [4]! words[i][j] words[j][i] words[i] words[i][0] none

  • If I have a function in python, say show(B), how would I code it so that...

    If I have a function in python, say show(B), how would I code it so that if B is a list like [3,3,4,0,0,8,2,0,0,5], it should return the elements in B that are not in range(len(B)). So the length of B in the given example is 10 so the range is from 0 to 9, so we want to return [0,1,2,5,6,9] since these are the values not in B. Thanks

  • I want to replace true with the number of comparisons that were made. For example, if...

    I want to replace true with the number of comparisons that were made. For example, if I have a list of [1,4,5,6,7,8] and I ask the program to find 6. is it possible to tell me how many comparisons it took to find 6?  PYTHON here is my code: def linear_search(vals,target):     for val in vals:         if val == target:             return True     return -1 def binary_search(vals,target):     lo = 0     hi = len(vals)-1     mid(lo+hi)//2     while lo <= hi and vals [mid]!=target:         if target...

  • I want to write a python function to find the minimum I have an nested list:...

    I want to write a python function to find the minimum I have an nested list: list = [[0,2,3], [1,6],[4,7]] I want to find out in minimum of each list and compare between each other then return the final minimum result for example: above the nested_list [[0,2,3], [1,6],[4,7,11]], for each set of the list the minimum would be [1,5,3] -> final return would be [1]

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