• 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 find most common element from list

Stats

  • Replies 1
  • Subscribers 143
  • Views 1170
  • Members are here 0

how to find most common element from list

jaapvds
jaapvds 3 months ago

I would like to find the most common/frequent element of a list.

Suppose I have following list: users = ("user1" "user2" "user3" "user1" "user1")

I would like to find the most frequent user, in this case user1. What SKILL function/method can be used for this?

thanks!

Jaap

  • Sign in to reply
  • Cancel
  • AaronSymko
    AaronSymko 3 months ago

    You can create a simple SKILL function to accomplish this, for example:

    procedure( findMostFrequentUser(listOfUsers "l")
    let((userTable (maxCount 0) maxUser)
    ;; Count the user occurrences
    userTable = makeTable('userTable 0)
    foreach(user listOfUsers
    userTable[user] += 1
    ); foreach
    ;; Get the maxUser
    foreach(user userTable
    when(userTable[user] > maxCount
    maxUser = user
    maxCount = userTable[user]
    ); when
    ); foreach
    maxUser
    ); let
    ); procedure

    users = '("user1" "user2" "user3" "user1" "user1")
    printf("Max user: %L\n" findMostFrequentUser(users))

    Running the above gives the following output:

    Max user: "user1"

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • 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