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

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, 0, 0, 0], [10, 30, 50, 80]]
A=Ci[1]([x for x in J if x not in J1])
print(A)

The error is

in <module>
    A=Ci[1]([x for x in J if x not in J1])

TypeError: 'list' object is not callable

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

[[[0, 0, 0, 0], [10, 30, 50, 80]],[[10, 50]]]

>Solution :

You can collect the indices first,

lidx = [i for i in range(len(J)) if J[i] not in J1]
A = [Ci, [Ci[1][i] for i in lidx]]
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