In python, if i have a list of words, take example "panda", how to replace 'a' with '-'?
the answer should be 'p-nd-'
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
In python, if i have a list of words, take example "panda", how to replace 'a'...
#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 length and Returns an empty list if there are no such words
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
which of the following expressions should replace [4]! words[i][j] words[j][i] words[i] words[i][0] none
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: 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]
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
In python Create a function that will take in an argument ( a 2D list of strings). The function will return a dictionary where the key is the first element of each row, and the key is the remaining elements. Example listOne ['aa', 'bb', 'cc', 'dd' ], ['ee', ff, 'gg', 'hh', 'ii', 'j' l ['kk', 'll', 'mm', 'nn' ] = Should return {'aa' : [ 'bb', 'cc', 'dd' ], 'ee' ff, 'gg', 'hh', 'ii, j' ] 'kk' : [ '',...
# python making a list of numbers i want to use python to make a list of numbers like this A = [2,2,4,4,6,6,8,8,10,10.....................48,48,50,50] # it should be a total of 50 numbers long and contain 2 of each even number
In python how would you write this to a file for example here the example output to be written to a file as and i want to use a LIST 0 < 20 20 < 40 40 < 60 60 < 80