list-manipulation

List of coordinates filtering

List of coordinates filtering Question: In python I have a list of contours (each holding x, y, w, and h integers), I need to somehow iterate over the list and check, if the current x + w is greater than the last x + w by less than 3 (which mean by 1 or 2) …

Total answers: 1

Keeping the structure of a list in after operating a nested loop

Keeping the structure of a list in after operating a nested loop Question: Suppose I have two lists as follow: x = [[‘a’,’b’,’c’],[‘e’,’f’]] y = [‘w’,’x’,’y’] I want to add each element of list x with each element of list y while keeping the structure as given in x the desired output should be like: …

Total answers: 3

Multiplying a list of integer with a list of string

Multiplying a list of integer with a list of string Question: Suppose there are two lists: l1 = [2,2,3] l2 = [‘a’,’b’,’c’] I wonder how one finds the product of the two such that the output would be: #output: [‘a’,’a’,’b’,’b’,’c’,’c’,’c’] if I do: l3 = [] for i in l2: for j in l1: l3.append(i) …

Total answers: 8

How to remove every occurrence of sub-list from list

How to remove every occurrence of sub-list from list Question: I have two lists: big_list = [2, 1, 2, 3, 1, 2, 4] sub_list = [1, 2] I want to remove all sub_list occurrences in big_list. result should be [2, 3, 4] For strings you could use this: ‘2123124’.replace(’12’, ”) But AFAIK this does not …

Total answers: 13

How can I get the concatenation of two lists in Python without modifying either one?

How can I get the concatenation of two lists in Python without modifying either one? Question: In Python, the only way I can find to concatenate two lists is list.extend, which modifies the first list. Is there any concatenation function that returns its result without modifying its arguments? Asked By: Ryan C. Thompson || Source …

Total answers: 7

Some built-in to pad a list in python

Some built-in to pad a list in python Question: I have a list of size < N and I want to pad it up to the size N with a value. Certainly, I can use something like the following, but I feel that there should be something I missed: >>> N = 5 >>> a …

Total answers: 14