Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare list

Status
Not open for further replies.

jloh81

Programmer
Jun 15, 2010
16
US
please see the attachment file

there is 2 line one is with io and one is x

how do i compare those 2 list?

I want to get the paramenter that not exsist at both list.

Here is my code:
if { $x == ""} {
puts "x is empty"
set x $i
continue
} else {
foreach i $io {
set y ""
puts $writefile1 "pin is $pin_name \n io is $io \n x is $x"
if {[lsearch -exact $x $i] == -1} {
lappend y $x
set pin $pin_name
puts $writefile2 "$pin --->\n $y"
}
}
set x $io
set x [list $x]
continue
}

Please advice

Test2.txt is file that i extract the result to.
test1.txt is file that contain both
 
I assume your question is as you state it: how to compare 2 lists and return the items not common to both lists.
Code:
set excplst {} 
for itm $lst1 {
    if {[lsearch $lst2 $itm]<0} {lappend excplst $itm}
}
for itm $lst2 {
    if {[lsearch $lst1 $itm]<0} {lappend excplst $itm}
}

_________________
Bob Rashkin
 
thanks for the suggestion.

But it still wont compare the 2 lists. I follow want you suggest to me. It return me, the code will append 2 list in one list for me. IT WONT COMPARE! i dont know where is going wrong? is it going wrong with when i set the list?
 
Sorry, I forgot which language we were using. Should be:
Code:
set excplst {}
for[red]each[/red] itm $lst1 {
    if {[lsearch $lst2 $itm]<0} {lappend excplst $itm}
}
for[red]each[/red] itm $lst2 {
    if {[lsearch $lst1 $itm]<0} {lappend excplst $itm}
}

Post the code you're using with code tags

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top