Home > Community > Forums > PCB SKILL > removing duplicate items on a list

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 removing duplicate items on a list 

Last post Sun, Jan 6 2013 4:51 PM by eDaNoy. 5 replies.
Started by D912349 25 Dec 2012 07:02 PM. Topic has 5 replies and 1185 views
Page 1 of 1 (6 items)
Sort Posts:
  • Tue, Dec 25 2012 7:02 PM

    • D912349
    • Top 150 Contributor
    • Joined on Sat, Nov 24 2012
    • Posts 46
    • Points 780
    removing duplicate items on a list Reply

    Hi everyone,

    Is their a function that that removes duplicates in a certain list?.

    example:

    input list is..

    listWithDuplicate = ( "a" "b" "c" "d" "a" "c" "d" "a" "a")

    after running the certain function, the output should look like this..

    newList =  ( "a" "b" "c" "d")..

    I am thinking of using looping statements but using loops will affect the time to run the program specially when the list consist of many items..

    Thanks in Advance..

    • Post Points: 20
  • Tue, Dec 25 2012 9:12 PM

    • GIL2004XP
    • Top 500 Contributor
    • Joined on Mon, Apr 25 2011
    • Dasi, 00-TW
    • Posts 24
    • Points 315
    Re: removing duplicate items on a list Reply
    You can try using the foreach function, see code below;
     
    newList = nil
    foreach( sel listWithDuplicate
    if( (member(sel newList) == nil) then
    newList = sort(cons(sel newList) 'alphalessp)
    )
    )

    • Post Points: 20
  • Tue, Dec 25 2012 10:34 PM

    • D912349
    • Top 150 Contributor
    • Joined on Sat, Nov 24 2012
    • Posts 46
    • Points 780
    Re: removing duplicate items on a list Reply

    Thanks GIL2004XP But what i need is a more straight forward function or maybe a built in function from allegro (if ever it exist).. My main concern is to decrease the time it takes for the program to remove duplicates, a list with 5 items will run fast.  but if my input is around hundreds or maybe thousands, I think it will run slower..

    • Post Points: 20
  • Wed, Dec 26 2012 9:21 AM

    • knuhcrek
    • Not Ranked
    • Joined on Tue, Jul 29 2008
    • Posts 7
    • Points 95
    Re: removing duplicate items on a list Reply

     Since you're trying to create a list of unique elements, why not use the unique() function? Something like

     

    newList = unique( listWithDuplicates)

     

    Another method would be to create a table and use the elements of listWithDuplicates as the keys. Then read all the keys into newList.

     

    Merry Christmas,

    Chris Walters

    rusty Cadence guru

    • Post Points: 20
  • Wed, Dec 26 2012 5:25 PM

    • D912349
    • Top 150 Contributor
    • Joined on Sat, Nov 24 2012
    • Posts 46
    • Points 780
    Re: removing duplicate items on a list Reply

    Thanks knuhcrek. unique function works perfectly. One more thing knuhcrek, can you tell me which documentation can I find the unique function??..

    • Post Points: 20
  • Sun, Jan 6 2013 4:51 PM

    • eDaNoy
    • Top 200 Contributor
    • Joined on Fri, Sep 9 2011
    • SBMA, Philippines
    • Posts 41
    • Points 940
    Re: removing duplicate items on a list Reply
    In addition to unique function, there is no compiled documentation about this function.
    • Post Points: 5
Page 1 of 1 (6 items)
Sort Posts:
Started by D912349 at 25 Dec 2012 07:02 PM. Topic has 5 replies.