nested-loops

inquire two information from the for loop python

inquire two information from the for loop python Question: For example I have this code : path_real = r’C:/Users/SLR CSV’ all_files_real = glob.glob(os.path.join(path , "2*.csv.zip")) list_real = [] for filename in all_files_real: df_real = pd.read_csv(filename, index_col=None, header=0, sep=’;’) list_real.append(df_real) So, my list_real is the collection of dataframe. And, If I want to do a for …

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

Returning a value based on index number of each element in a list

Returning a value based on index number of each element in a list Question: I am trying to identify the first element, last element, and other elements in a python list using a function. If it’s the first element, I want 0 to be returned, if it’s the last element I want -1 to be …

Total answers: 1

For loop to append list of strings to lists within nested list

For loop to append list of strings to lists within nested list Question: [enter image description here][1]I have a dataset that is a list of 3 nested lists (called "patients"). Each nested list contains a certain amount of observations. The first nested list contains 119 observations, the second one 9 and the third list contains …

Total answers: 2

What's the exact distinction between the FOR loop and the WHILE Loop

What's the exact distinction between the FOR loop and the WHILE Loop Question: I understand that loops are an integral part of any programming language. They help us to iterate tasks that are repetitive. But I don’t seem to understand why these 2 loops are required seperately. Can’t just one of them do the job? …

Total answers: 5

Using the same iterator in nested for loops

Using the same iterator in nested for loops Question: Consider the following code: from itertools import chain lst = [‘a’, 1, 2, 3, ‘b’, 4, 5, ‘c’, 6] def nestedForLoops(): it = iter(lst) for item0 in it: if isinstance(item0, str): print(item0) else: # this shouldn’t happen because of # 1. lst[0] is a str, and …

Total answers: 2

Nested loop provides unwanted action

Nested loop provides unwanted action Question: I am trying make a nested loop so a while loop gets repeated n times. An object is supposed to drive a distance in i steps for n repetitions. Axis and speed are irrelevant for the loop. What I don’t understand is why the first i in i = …

Total answers: 1

Iterate a nested dictionary and filter specific fields

Iterate a nested dictionary and filter specific fields Question: I have an example object which is mixed of lists and dicts: { "field_1" : "aaa", "field_2": [ { "name" : "bbb", ….. "field_4" : "ccc", "field_need_to_filter" : False, }, { "name" : "ddd", ….. "details": [ { "name" : "eee", …. "details" : [ { …

Total answers: 2