Sunday 15 June 2014

duplicates - Keeping common elements from two list in tcl and place them in a result list -


I have a list of two different lengths in which integers are now duplicates within a list when viewed on two lists. Duplicate such as

  set list A [list 3 4 9 2 2 6 6] set list B [list 34 43 9 12 2 10 61 88 23 48]   

Is there an effective quick way to create a new list, which contains only the numbers in the original list? In this case: [9 2 10]

I do not want to use the nested loop because the list can be large, I first thought about sorting them and then comparing the element's element by them. Are there. However, it only works when both lists are of the same length ....

See more. It works for Tcl 8.0 and still works on 8.5 (and I'm pretty sure that 8.6 too).

 % package is required Tcl% package struct :: set% set ListA [list 3 4 9 1 2 10 6]% set ListeB [List 34 43 9 12 2 10 61 88 23 48]% :: straight :: set $ list $ list B 9 2 10    

No comments:

Post a Comment