有没有一种方法可以通过使用Python Lambda降至创建的时间进行排序?
我正在与Sqlalchemy合作查询包含事件列表的数据库。每个事件都有创建的时间和一个ARI(亚马逊资源编号)。我可以从一个函数调用中返回最多记录,我想从最新的第一个开始回到记录。为此,我需要手动传递正确对记录的lambda函数;该参数的文档在这里:
cols (default=None):
A function which takes a DBObject class and returns a tuple of columns (or SQLAlchemy
expressions) used to compare it. This overrides the default sorting behaviour.
Example: key=lambda x: (x.created, x.ari)
如您所见,默认情况下,它按X.创建,然后按X.Ari进行升级。实际上,我需要做与此相反的事情,然后按X.创建,然后按x.ari进行排序,以 descing 顺序进行排序。有什么办法可以用lambda做到这一点?使用STROT()或排序()并不是我使用此预先存在的功能的选择。
I'm working with SqlAlchemy to query a database containing a list of events. Each event has a created time and an ari (amazon resource number). There's a maximum number of records I can get back from one function call, and I want to get back the records starting with the most recent first. To do this I need to manually pass in a lambda function that sorts the records properly; documentation for the argument is here:
cols (default=None):
A function which takes a DBObject class and returns a tuple of columns (or SQLAlchemy
expressions) used to compare it. This overrides the default sorting behaviour.
Example: key=lambda x: (x.created, x.ari)
As you can see, by default it sorts by x.created, then x.ari, both in ascending order. I actually need to do the opposite of this and sort by x.created, then x.ari, in descending order. Is there any way I can do this with just a lambda? Using sort() or sorted() is not really an option due to me using this pre-existing function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论