nested-loops

Update one list with respect to another list in python

Update one list with respect to another list in python Question: I’m very new in python. I just stuck in one problem. I have two lists, like – list1 = [1,2,3,4,5] list2 = [3,6,8,9,1,2,4,0,5] Now I have to check each value of list1 with that it is present in list2 or not. If all the …

Total answers: 1

How to avoid nested for loops in NumPy?

How to avoid nested for loops in NumPy? Question: I have this code. n_nodes = len(data_x) X = np.zeros((n_nodes, n_nodes)) for i in range(n_nodes): for j in range(n_nodes): X[i, j] = data_x[i] ** j I want to do the same task with no loops used at all. How can I do that with NumPy functions? …

Total answers: 3

Nested for loop with if in one line for creating new column in dataframe

Nested for loop with if in one line for creating new column in dataframe Question: I have a dataframe "result" and want to create a new column called "type". The value in "type" will be the item value of a dict if the column "Particulars" in the dataframe contains value of the key. dict_classify={‘key1’: ‘content1’, …

Total answers: 3

Iteration via expandable nested 'for' loops without itertools

Iteration via expandable nested 'for' loops without itertools Question: I am trying to make a list of iterations of the alphabet with itself to the n-th power but I am unable to find an appropriate way of achieving this. I would rather not use itertools for the time being. My idea is as follows, although …

Total answers: 1

Trying to check a list of list against multiple other lists

Trying to check a list of list against multiple other lists Question: I have a 100,000 entry list of lists derived from a CSV that is derived from a firewall log. My vision is to end with a file that outputs the ports used between any two IPs, such as: 1.1.1.1. to 2.2.2.2 ports (25, …

Total answers: 2

Nested Loop Optimisation in Python for a list of 50K items

Nested Loop Optimisation in Python for a list of 50K items Question: I have a csv file with roughly 50K rows of search engine queries. Some of the search queries are the same, just in a different word order, for example "query A this is " and "this is query A". I’ve tested using fuzzywuzzy’s …

Total answers: 3

Updating a 2D Array with the output results of a nested loop in Python

Updating a 2D Array with the output results of a nested loop in Python Question: I have a nested loop where I calculate 10 distances, and store them in an array b_array. Then into a_array another array which will is to keep the results for every image. The problem is that my code overwrites a_array …

Total answers: 1

How to nest loops N number of times python

How to nest loops N number of times python Question: I’m creating a program, which needs to nest loops N number of times. Is there any way to do this? Or do I need to do it manually? Wanted result: for i in range(N): #Do something for i in range(N-1): #Do something for i in …

Total answers: 1