comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » lambda functions in IDL-python bridge
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
lambda functions in IDL-python bridge [message #91857] Fri, 04 September 2015 06:55 Go to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
Hi,
I've got the next problem, using a lambda function in the python sorted function.

Consider this easy python example:

d0 = {'sorted': 1, 'unsorted': 0}
d1 = {'sorted': 5, 'unsorted': 1}
d2 = {'sorted': 3, 'unsorted': 2}
d3 = {'sorted': 7, 'unsorted': 3}
d4 = {'sorted': 4, 'unsorted': 4}
l = [d0,d1,d2,d3,d4]
sorted(l, key = lambda x:x['sorted'])

The result would be:
[{'sorted': 1, 'unsorted': 0},
{'sorted': 3, 'unsorted': 2},
{'sorted': 4, 'unsorted': 4},
{'sorted': 5, 'unsorted': 1},
{'sorted': 7, 'unsorted': 3}]

Now if I would want to do this in IDL, things would get difficult. Suppose I get a dictionary (or a simple object with a property...) as a result of an operation and I want to sort this result according to a specific property... how do I do that in IDL?

The synthax:
matches = Python.sorted(matches, key = lambda(x: x.distance))

will give me a compilation error.

Thanks,
Helder

PS: I found a different solution to this problem using IDL. I import all properties in an idl variable, sort the variable and apply this to the list. A python solution would be though nice, just to know how to deal with lambda functions.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: using IDLnetURL to get an image from a HTTP URL into IDL
Next Topic: problem with DLM using external DLL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:47:59 PDT 2025

Total time taken to generate the page: 0.00437 seconds