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

Remove List from List of List and generate a new List

The problem seems very easy, but unfortunately I can’t solve it.

Let list A = [[1,2,3], [4,5,6], [7,8,9], [10,11,12], [13,14,15]]

I want to create a new list by removing list [7,8,9]

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

The remove is not creating a new list: A.remove(2)

And set(A) - set([7,8,9]) throwing the following error.

TypeError: unhashable type: 'list'

Can someone please help me to solve the issue?

>Solution :

If you absolutely needs to remove based on indice and not value, it may be done with a list comprehension:

A = [value for i,value in enumerate(A) if i != 2]
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