# adding a new value to list overwrite previous values in the list

I’m trying to add multiple items to a list but at the end all items have the same value equal to last item public static List<Ausencias> SeparateMonth(Ausencias aus) { List<Ausencias> ausencias = new List<Ausencias>(); try { var resultSplit = Helper.SplitFechas(aus.PI_StartDate, aus.PI_EndDate); if (resultSplit.Count > Constant.ONE) { foreach (var item in resultSplit) { Ausencias ausenc =… Read More adding a new value to list overwrite previous values in the list

# Generating a list based on other lists in Python

I have two lists A2 and J. I am performing an operation such that whenever J[0][i]=0, A3==[0]. I present the current and expected output. A2 = [[2, 3, 5], [3, 4, 6], [0, 3, 5], [0, 1, 2, 4, 5, 6], [1, 3, 6], [0, 2, 3, 7, 8, 10], [1, 3, 4, 8, 9,… Read More Generating a list based on other lists in Python

# Creating multiple sublists by performing an operation in Python

I have two lists A2 and Cb_new. I am performing an operating as shown below. But I want to create multiple sublists instead of one single list. I present the current and expected outputs. A2=[[2, 3, 5], [3, 4, 6]] Cb_new=[[1.0, 0.0, 0.0, 0.9979508721068377, 0.0, 0.9961113206802571, 0.0, 0.0, 0.996111320680257, 0.0, 0.0]] Cb=[] for j in… Read More Creating multiple sublists by performing an operation in Python

# How do I find the combination of values in an array that gives the highest sum

I’m trying to write a code that takes an array of integers, then returns the maximum sum you can get from different combinations of the values in the integer. I also want to be able to see the particular combination that gives this as well. And with the logic behind it if possible What I… Read More How do I find the combination of values in an array that gives the highest sum

# Locating index of one list with respect to another list in Python

I have lists J1 and J2. I want to locate the index of elements of J2 with respect to J1. For example, J2[0]=2 and this occurs at J1[1]. Hence, the index should be 1. Similarly for other elements of J2. I present the current and expected outputs. import numpy as np J1=[[1, 2, 4, 6,… Read More Locating index of one list with respect to another list in Python

# Expand a comma separated item in a list

I have two python lists of the following form: grocery_list = ["apple", "whole milk, skim milk, 2% milk", "american cheese, cheddar cheese"] grocery_cost = [10.5, 4.50, 2.40] and I would like to convert them to a more easily read from list of the form: grocery_list = ["apple", "whole milk" , "skim milk", "2% milk", "american… Read More Expand a comma separated item in a list

# Python delete all elements from a list that are on an odd index

I’m trying to delete all elements from a Python list that are on an odd index of the list. In my case, the result from len(elements) is 40, so I assume after deleting all odd indexes, the total length should be 20. I tried the following code: indx = 0 for element in elements: if… Read More Python delete all elements from a list that are on an odd index

# Removing elements from a list based on indices in another list in Python

I have a list J. I want to remove specific elements from J[0] based on index. For example, I want to remove J[0],J[3] based on elements in index. But I am getting an error. I present the expected output. J=[[2, 6, 9, 10]] index=[[0,3]] for i in range(0,len(J)): for k in range(0,len(index)): J[i].remove(index[k][0]) print(J) The… Read More Removing elements from a list based on indices in another list in Python

# Performing a list operation in Python

I am removing J1 from J. Corresponding to the removed indices, I want to alter Ci[1] and append to Ci as shown below but I am getting an error. I also present the expected output. J=[2, 6, 9, 10] J1=[6,10] l=[] l.append(J) l.append([x for x in J if x not in J1]) Ci = [[0,… Read More Performing a list operation in Python

# Appending the removed elements to a list in Python

I am removing J1 from J but I also want to append the two. I present the current and expected output. J=[2, 6, 9, 10] J1=[6,10] for i in range(0,len(J1)): J.remove(J1[i]) J.append(J) print(J) The current output is [2, 9, […], […]] The expected output is [[2, 6, 9, 10],[2,9]] >Solution : l=[] l.append(J) l.append([x for… Read More Appending the removed elements to a list in Python