• 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 sort list of lists?

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 144
  • Views 9035
  • 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 sort list of lists?

Sheppie
Sheppie over 2 years ago

Hello.

In order to automatically number devices, I have written code to extract all relevant data from a cell-view and store it in a list of lists. The list of lists looks something  like this:

list( '(23.5 nameA cellId) '(18.3 nameB cellId) '(73.0 nameC cellId) '(23.5 nameD cellId) '(44.9 nameE cellId))

where every cellId is unique, and the first value may appear multiple times (like the 23.5 value), in that case the order has to follow the name (names are unique)

In order to give each cell the proper number, I have to order this list, the first element defines the order, then the name. It should look like this:

list( '(18.3 nameB cellId) '(23.5 NameA cellId) '(23.5 nameD cellId) '(44.9 nameE cellId) '(73.0 nameC cellId))

Sorting a simple list of values is easy. I can think of complicated code to sort my list, however, I can imagine that there is a way simpler method of doing it.

Does anyone have a idea how I could efficiently sort my list?

If this is rather complicated, I think I can make the rest of my code to work with only sorting defined by the first element, so ignoring the name.

Thanks in advance.

With kind regards,

Sjoerd

  • Cancel
Parents
  • AurelBuche
    AurelBuche over 2 years ago

    Hi,

    If you want to sort the list by comparing the first elements, you can use the following command :

    (sortcar your_list 'lessp)

    Otherwise you just have to define a custom comparison function :

    (sort your_list
      (lambda (l0 l1)
        ;; Compare l0 and l1 by first element, or by name when they are equal
        (destructuringBind (n0 name0 cell0) l0
          (destructuringBind (n1 name1 cell1) l1
            (if (equal n0 n1) (alphalessp name0 name1) (lessp n0 n1))
            ))))

    Cheers,

    Aurel

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sheppie
    Sheppie over 2 years ago in reply to AurelBuche

    Hi Aurel,

    Thank you for you quick response. I've tried your code and it works! It does what I'd like it to do.

    I'll definitely have to spend time to understand your code (never seen the destructuringBind procedure...) and learning something, so thank you for sharing this.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Sheppie
    Sheppie over 2 years ago in reply to AurelBuche

    Hi Aurel,

    Thank you for you quick response. I've tried your code and it works! It does what I'd like it to do.

    I'll definitely have to spend time to understand your code (never seen the destructuringBind procedure...) and learning something, so thank you for sharing this.

    With kind regards,

    Sjoerd

    • 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