[Python] How to find the short list from a long list if the elements in the short one are all...

Discussão em 'Python' iniciado por Stack, Setembro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have a nested list:

    a=[[1,2,3],[0,1,2,3,4],[5,7,9],[5,6,7,8,9],[7,10],[10,7,2,1]]


    Now, I want to delete [1,2,3] because it is included in [0,1,2,3,4]. And I need to keep [5,7,9] because although it is included in [5,6,7,8,9] but there are some numbers in between. Also, [7,10] should be kept too because these numbers are in the wrong order in [10,7,2,1]. So, the simplified list is:

    a=[[0,1,2,3,4],[5,7,9],[5,6,7,8,9],[7,10],[10,7,2,1]]


    So, I need to delete the short sub lists if they are included in the long ones without any changes. How can I do that?

    Continue reading...

Compartilhe esta Página