Skip to content
Advertisement

Tag: list

Python replace() – how to avoid repeating replace()?

There are some elements in the sorted_elems list which will be changed to str such as: sorted_elems = [‘[abc]’, ‘[xyz]’, [‘qwe’]] I want to remove the defined characters – [, ], ‘ and print the output below: So the output should look like this: abc, xyz, qwe. My solution to achieve it was: And it works fine, but the question

Using Recursion to check for sum of tuples in a list

I have a func which takes a list of tuples, each tuple contains two items: item name and value. I need the func to return True if it’s possible to divide the tuple list into two equal valued groups and False otherwise. The function should be recursive and should not use any loops. for example, should result in True, because

word search in python :a search which return the indices the letters

#the following program checks the words in a 2D array and returns a nested list of the indices of the words.the algorithm checks the words in horizontal direction(left &right),vertical direction (upward and downward) and diagonally(left to right in the downward direction) **problem that i’am facing ** #the program returns correct indices for some of the words but for some it

Iterative summation

I’m trying to write a python code that allows me to iteratively sum up the average values of three elements of a list, starting with the third element and its two predecessors. Let me give you an example: I want to calculate the following: Since I’m quite new to programming I couldn’t find an effective way of putting this into

Is there a way to fix value-error problem

Hello guys i am trying to implement an algortihm to remove water from underwater images and make image more noticable , but i got an errror ValueError: max() arg is an empty sequence , at the function homomorpic on this line r = max(np.ravel(result[:,:i])) , the error is caused because the result array is empty but i filled it above

Advertisement