Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Appending values in a specific format to a list in Python

I have two lists. I am writing a condition to find index values when MaxPrnew > Pr_cap_t and appending it as shown below. I present the current and expected outputs.

Pr_cap_t=[5051.061086369891,
 5046.295040175788,
 5072.5758312061325,
 5055.713625152885,
 5056.625327627877]

MaxPrnew=[241.08095445711552,
 1726.9903228626436,
 1232.262749719154,
 484.3360494454877,
 1232.262749719154]


Cond_t=[]
false_indices = [[]]

for i in range(len(MaxPrnew)):  
    Cond1 = MaxPrnew[i] > Pr_cap_t[i]
    Cond_t.append(Cond1) 
    if not Cond1: 
        false_indices.append(i)

print("false_indices =",false_indices)

The current output is

false_indices = [[], 0, 1, 2, 3, 4]

The expected output is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

false_indices = [[], [0, 1, 2, 3, 4]]

>Solution :

Pr_cap_t=[5051.061086369891,
 5046.295040175788,
 5072.5758312061325,
 5055.713625152885,
 5056.625327627877]

MaxPrnew=[241.08095445711552,
 1726.9903228626436,
 1232.262749719154,
 484.3360494454877,
 1232.262749719154]

k = [x for x,y in enumerate(zip(Pr_cap_t, MaxPrnew)) if y[0] > y[1]] # your program logic can be used in a list comprehension

false_indices = [[]]

false_indices.append(k)

false_indices
#[[], [0, 1, 2, 3, 4]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading