×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Python Script: Sorted Sets

Python Script: Sorted Sets

Python Script: Sorted Sets

(OP)
Hello!

Currently I'm working on a Python script and I'd like to know whether it is possible to create sets with entries sorted by a particular criterion?

In my case I need a node set with nodes arranged by their y-coordinates. Is it possible, for example, to generate a list of node labels, to rearrange the entries of the list and to create a set from that list afterwards?

Thanks a lot!

RE: Python Script: Sorted Sets

Hi PeterP1,

Look for unsorted node sets in the manual.

Once you have sorted your node list as needed, you can create a so called "unsorted node set" out of it ("unsorted" because it is not sorted by node label). As unsorted node sets are not supported by /CAE, you'll probably have to use the keyword editor in some way in your script to add the set to your input file.

Hope this helps,

potf

RE: Python Script: Sorted Sets

(OP)
I know about unsorted sets but this works with keywords only. Using the keyword editor in a script is possible but it makes things more complicated. Therefore I'd like to avoid it. If there is no other possibility your solution is the best one, I guess.

Thank you potf!  

RE: Python Script: Sorted Sets

Hi to all Pyoneers!
PeterP1, you can check this pack:
 http://pypi.python.org/pypi/sorteddict/1.2.1
Or code your own iterator using heaps:
http://en.wikipedia.org/wiki/Heap_(data_structure)
Right now python hasnt its own built-in implementations of sorted collections.
Also, if you are using JPython, you can use those java built-ins:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html
http://java.sun.com/javase/6/docs/api/java/util/SortedSet.html
http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources