• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. how to remove repeat element in a list

Stats

  • Locked Locked
  • Replies 13
  • Subscribers 145
  • Views 23646
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to remove repeat element in a list

tomchen
tomchen over 12 years ago

Hi 

I want to remove repeated element that in a list, but I can't find the related function for this.

I try to use hash table to solve it , but the order of this list will be changed

does any other function for this ??

ex:

                                                      change to 

aa= list("AA" "AA" "AA" "BB" "BB")  -----------------> aa = list("AA" "BB)

 

  • Cancel
Parents
  • jimka
    jimka over 11 years ago

    HI Derek, an interesting varient of removing duplciates from a list comes up when you slightly relax the meaning of duplicate.  For example, suppose you want to look at a list of strings, removing duplicates, but looking at the strings in a case independenty way. For exmaple, you might consider "AAA", "Aaa", and "aaa" to be duplicates.   Here is how you might do it.  First generalize SkxUniquify so that it can use a function other than equal to compare two elements.  Thereafter, use this generalized SkxUniquify to implement SkxRemoveDupStringsCi ...

    (defun SkxUniquify (data @key (cmp equal))
      (mapcon (lambda (data)
                (unless (exists item (cdr data)
                          (cmp item (car data)))
                  (ncons (car data))))
              data)) 

    (defun SkxRemoveDupStringsCi (strings)
      (SkxUniquify strings
                   ?cmp (lambda (a b)
                          (equal (lowerCase a)
                                 (lowerCase b))))) 

    (SkxRemoveDupStringsCi '("Aaa" "AAA" "AAA" "ABC" "abc" "aaa" "AAA")) 
    => ("abc" "AAA")

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • jimka
    jimka over 11 years ago

    HI Derek, an interesting varient of removing duplciates from a list comes up when you slightly relax the meaning of duplicate.  For example, suppose you want to look at a list of strings, removing duplicates, but looking at the strings in a case independenty way. For exmaple, you might consider "AAA", "Aaa", and "aaa" to be duplicates.   Here is how you might do it.  First generalize SkxUniquify so that it can use a function other than equal to compare two elements.  Thereafter, use this generalized SkxUniquify to implement SkxRemoveDupStringsCi ...

    (defun SkxUniquify (data @key (cmp equal))
      (mapcon (lambda (data)
                (unless (exists item (cdr data)
                          (cmp item (car data)))
                  (ncons (car data))))
              data)) 

    (defun SkxRemoveDupStringsCi (strings)
      (SkxUniquify strings
                   ?cmp (lambda (a b)
                          (equal (lowerCase a)
                                 (lowerCase b))))) 

    (SkxRemoveDupStringsCi '("Aaa" "AAA" "AAA" "ABC" "abc" "aaa" "AAA")) 
    => ("abc" "AAA")

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information