compare two list and display the different elemts

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

hi all,

set a '1 2 3 '

set b ' 4 1 3 8 2'

 i need to compare these two lists ...not on the basis of order of arrangement only difference 

output i need is  4  8

 

i tried using using *markintersection its not working

Find more posts tagged with

Sort by:
1 - 7 of 71
    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi

    *markintersection is used for hm entities only.

    a proc like this

    proc ::ldiff {list1 list2} {

         set result {}

         foreach item $list1 {if {[lsearch $list2 $item]==-1} {lappend result $item}}

         set result

    }

    #now call

    ldiff $b $a

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

     

    hi tinh ,

    ya this is working....in case if we have

    set a '1 2 3'

    set b '1 3 4'

    out put

    2 4

    in this case we have to loop both the lists and append in a separate list . ryt?

     

    User: "tinh"
    Altair Community Member
    Updated by tinh

    just try it and show us your results

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    just try it and show us your results

    chào Tĩnh, mình mới học về hypermesh và đang muốn viết script cho hypermesh, bạn học về hypermesh à :D/emoticons/default_biggrin.png' srcset='/emoticons/biggrin@2x.png 2x' title=':D' width='20' />

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    hi  tinh,

    in the code which u have written ,what does set result does.?(after the for loop)

     

    User: "tinh"
    Altair Community Member
    Updated by tinh

    it returns result.

    i think it is not neccessary. because lappend will return it

    could you remove it and try?

    User: "tinh"
    Altair Community Member
    Updated by tinh

    no no, it is needed. because sometimes lsearch not found item, it will return emptied string