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
Tag: list
How do I merge several 2D arrays into a single 2D array (list) in a box-like manner in python?
Say I have 9 2D arrays in the following format: and I want to concatenate them to get a 2D array like this: where I will have N arrays in my case and I calculate the value of N like so: So essentially, I had an image that was broken down into N tiles and after some processing, I have
Pythonic way to extract keys and multiple values from a list of dicts
I have some code which works, data is read in from a text file as a list of dicts, the code takes the keys and values from each dict in for loops. While it works I am sure there is a better way to do it than mine below: Code Outputs Answer I would recommand using pandas.DataFrame very convenient way
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
How to create a list of images and their names in a folder
I am using the following code to create a list of image files with tif extension. The current result of the code is a list with the address of the .tif files. result: How can I revise the code to create two lists a) name of the file with .tif b) name of the file. here is the example: edit
Modifying an item in a list of lists, changes also other lists same item position
The following code is part of a function but the problem I have is on these lines. and this generates a list of lists as: If for example I want to modify only the second value in the second item from the second list: Is not only changing the desired value but also other lists values in the same index
Get all possible combinations between two lists, including multiple connections
With I get the 16 possible individual combinations of the lists l1 and l2, [(1,1), (1,2), … ] etc. Is there a way to also get combinations that ‘connect’ the lists in multiple ways? For example, I could have the following combinations [(1,1), (2,3)], [(1,3), (2,4), (3,2)], and [(1,2), (2,4), (3,3), (4, 1)]. Any help would be greatly appreciated. Answer