• 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. Finding and counting duplicates in a list

Stats

  • Locked Locked
  • Replies 7
  • Subscribers 144
  • Views 17873
  • 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

Finding and counting duplicates in a list

LakshmanQual
LakshmanQual over 7 years ago

Hi Team, 

If my list had ("a" "b" "c" "a" "d" "f" "a" "c" "b"), then it should give a=3,b=2,c=2. No need to give 'd' and 'f'.

How to code in Cadence SKILL to find the duplicates count?

  • Cancel
Parents
  • Marcel Preda
    Marcel Preda over 7 years ago

    procedure( MpFindDuplicated( lx )
    let( (myTable)
    myTable = makeTable("myTable" 0)
    foreach( e lx
    myTable[e] = 1 + myTable[e]
    )

    foreach( e myTable~>?
    if( myTable[e] == 1 then
    remove(e myTable)
    )
    )
    ;; return value
    myTable
    )
    )

    myList = list("a" "b" "c" "a" "d" "f" "a" "c" "b")
    duplicated = MpFindDuplicated(myList)
    printf("%L\n" duplicated~>??)

    Output will be something like : ("a" 3 "b" 2 "c" 2)

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to Marcel Preda
    Marcel Preda said:
    foreach( e myTable~>?
    if( myTable[e] == 1 then
    remove(e myTable)
    )

    Marcel - a small change - you don't really need to do myTable->? here because if you do a foreach over a table the loop variable will be set to each key anyway. So you can just do:

    foreach(e myTable
    ...
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to Marcel Preda
    Marcel Preda said:
    foreach( e myTable~>?
    if( myTable[e] == 1 then
    remove(e myTable)
    )

    Marcel - a small change - you don't really need to do myTable->? here because if you do a foreach over a table the loop variable will be set to each key anyway. So you can just do:

    foreach(e myTable
    ...
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • LakshmanQual
    LakshmanQual over 7 years ago in reply to Andrew Beckett

    Hi Andrew,

    The code is not working. As its throwing error for make table command. Showing "undefined function: myTable"

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to LakshmanQual
    LakshmanQual said:
    The code is not working. As its throwing error for make table command. Showing "undefined function: myTable"

    You must have made a typo somewhere - the code above that Marcel gives (or my suggested modification) can't cause that error.

    My guess is that somewhere  you have (myTable) or myTable() - with parentheses around the name (not sure where you've done this). Perhaps you can paste the code which is failing and the exact error you're getting?

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Marcel Preda
    Marcel Preda over 7 years ago in reply to LakshmanQual

    Please double check that you use square brackets where it is needed. E.g. myTable[e] , and not myTable(e)

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • LakshmanQual
    LakshmanQual over 7 years ago in reply to Marcel Preda

    Hi Marcel and Andrew, Thanks for the script. Its working fine.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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