compare within a list

Sathish_21542
Sathish_21542 Altair Community Member
edited October 2020 in Community Q&A

Hi,

I have a list of elements with ids as:

set elementlist { {100 101} {1000 1001} {101 100} {1001 1000} }

I need to check for duplicate ids within the list. whichever item is existing twice should be written as output.

 

expected output:

{100 101} {1000 1001}

or

{101 100} {1001 1000}

Can anyone help me with this? 

Thanks in advance!

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited December 2018

    Hi

    foreach item $elementlist {

        If {[llength [lsearch -all $elementlist $item]]>1} {puts $item}

    }