- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在尝试对字典列表进行排序并使用 attrgetter 进行排序,但它显示 attrgetter 未定义。
>>> a = ['{"count": 1, "places": [{"lat": 12.99455070495605, "lng": 77.6714096069336, "address": "Karnataka, India"}], "created_at": "2015-03-17 04:25:10", "updated_at": "", "environments": [{"display_address": "Karnataka, India", "name": "", "views": 0, "country": "India", "region": "Karnataka", "address": "4th Cross Street, Mottappa Compound, A Narayanapura, Mahadevapura, Bengaluru, Karnataka 560016, India", "comments": 0, "height": 758, "width": 1008, "image_url": "http://9cb448a50dcef7c3d28e-10dfb1f9ec7a490e45082ae9c51f52eb.r27.cf1.rackcdn.com/photos/4185354/ff90ae45348134c1345c49b2c853a31e.jpg", "likes": 0, "photo_where": "", "lat": 12.99455070495605, "photo_type": "panorama", "lng": 77.6714096069336, "thumb_url": "http://0f9cb149e5cc61745fd5-2870fdbe0c753e4bc418911d9614db21.r17.cf1.rackcdn.com/thumbs/534901/", "tiles_url": "http://c6c0b88e96acc3346aff-c40106bef0a12d7839dc46608748511d.r69.cf1.rackcdn.com/tiles/534901/", "id": 534901, "is_spherical": 0, "source": {"fov": 123.867, "scale": 0.0, "startx": 0, "vertical_fov": 39.4, "starty": 0}}], "user": {"profile_pic_url": "http://22d39cd6accfe73dc8bf-8a3f41b0dadcd18fc1e3dc2022064b19.r29.cf1.rackcdn.com/panographers/panographers_default_07S.png", "id": 4185354, "profile_url": "http://www.teliportme.com/profile/moto.teliportme", "name": "moto.teliportme"}, "photo_type": "panorama", "type": "upload"}', '{"count": 1, "places": [{"lat": 12.99455547332764, "lng": 77.67140197753906, "address": "Karnataka, India"}], "created_at": "2015-03-17 04:25:19", "updated_at": "2015-03-18 06:22:08", "environments": [{"address": "4th Cross Street, Mottappa Compound, A Narayanapura, Mahadevapura, Bengaluru, Karnataka 560016, India", "height": 750, "is_spherical": 0, "likes": 1, "lng": 77.67140197753906, "id": 534902, "user_id": 4185354, "source": {"fov": 138.302, "scale": 0.0, "startx": 0, "vertical_fov": 39.4, "starty": 0}, "tags": [{"category": "admin", "environment_id": 534902, "name": "popular", "tag_id": 15138}], "comments": 0, "width": 1273, "tiles_url": "http://71d4e0cc9d7caffc7e21-1f1149a3ba6cc477dd90c37b0398406a.r26.cf1.rackcdn.com/tiles/534902/", "display_address": "Karnataka, India", "views": 0, "photo_where": "", "lat": 12.99455547332764, "photo_type": "panorama", "thumb_url": "http://30f287b674c32ae6d7d0-4c458530dcb1ef77c889ef5a5d185cb3.r35.cf1.rackcdn.com/thumbs/534902/", "name": "", "country": "India", "region": "Karnataka", "image_url": "http://72dd3f16a93e55ea7eb9-e4ef3340595b2ac7356e5ba4ff95e48d.r89.cf1.rackcdn.com/photos/4185354/b771316a647b04413e5a7bd09497582d.jpg"}], "user": {"profile_pic_url": "http://22d39cd6accfe73dc8bf-8a3f41b0dadcd18fc1e3dc2022064b19.r29.cf1.rackcdn.com/panographers/panographers_default_07S.png", "id": 4185354, "profile_url": "http://www.teliportme.com/profile/moto.teliportme", "name": "moto.teliportme"}, "photo_type": "panorama", "type": "upload"}']
>>> a = sorted(a, key=attrgetter('likes'), reverse=True)
最佳答案
attrgetter
是 operator
模块中标准库的一部分,而不是内置函数。因此,您需要 import attrgetter
from operator
.
from operator import attrgetter
关于python - 名称错误 : name 'attrgetter' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29120240/
我正在尝试添加 ace editor到我的应用程序。我从 github 下载它,将“ace/lib/ace”目录放到我的应用程序目录中,包括: " 在我的正文标签中: editor = ace.edi
如果有人能介绍一下 TypeScript 1.8 模块,我将不胜感激。 我有 SomeClass.ts 文件: export class SomeClass { } 然后,在我的 app.ts 中导入
今天,当我阅读php内核代码时,在目录:php5.3/Zend/Zend.h中,有一行代码让我很困惑。 代码如下: /* overloaded elements data types */ #defi
今天看php的内核代码,在php5.3/Zend/Zend.h目录下,有一行代码搞得我一头雾水。 代码如下: /* overloaded elements data types */ #define
我有一个相当大的项目,我试图将所有 JS 文件连接到一个文件中。我已经能够做到这一点,但我在实际将这两个文件实现到代码中时遇到了麻烦。 我的 Gruntfile 有一个执行串联的任务: require
1在以下示例中似乎没有必要(并且可能具有误导性),但是在用于检查 #ifdef 时我已经多次看到这种情况s: #ifndef __NEWLIB_H__ #define __NEWLIB_H__ 1 使
感谢您提供的任何帮助。我有一个 Grails 项目,我正在尝试将 Karma 安装到其中。但是,当我运行时 ./gradlew 构建 我收到以下错误: [x-10-105-56-234]SENG519
我从 Frontend Developer Interview Coding Questions 得到了这个问题.为什么下面的代码片段会打印它打印的内容?我最初认为它会抛出一个 ReferenceEr
之前的问题描述有歧义,所以我在下面修改了一些东西。谢谢。 我想像这样实现一些宏: #define AddVariable(x) \ #define x (++counter) class Ba
我知道我正试图朝自己的腿开枪 ;) 但是,它可以让我使其余(大量)代码更小且更易读。 有什么技巧可以在另一个预处理器宏中创建预处理器宏吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's
在 Microsoft 的 WinDef.h 中引入了几个用于回调的#defines: #ifdef _MAC #define CALLBACK PASCAL #define WINAPI
我知道我想在腿上开枪;)但是,它可以让我使其余(大量)代码更小且更具可读性。 在另一个预处理器宏中创建预处理器宏有什么棘手的方法吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's wh
当我使用这段代码时: #include #define STR(x) #x int main(void) { printf(__FILE__ STR(__LINE__) "hello!\n"
今天的问候, 您好,我是使用 vb 6.0 的初学者。我正在使用以下代码并获得“用户定义类型未定义”。代码在下面。我得到错误的行被突出显示。请帮助。我应该添加一些引用或组件吗?如果是这样,它会是什么。
当我尝试编译此代码时,在 VB6 中出现编译错误“用户定义的类型未定义”。谁能告诉我需要做什么来解决这个错误?以下是我收到错误的行: Public Conn As ADODB.Connection P
我最近将我的应用程序从 Ember 1.3 升级到了 Ember 2.4.2。然而,在使用 ember build --env production 将其部署到我的生产环境后,我注意到了一些问题。 第
这个问题在这里已经有了答案: Getting user-defined type not defined error when running code (2 个回答) 3年前关闭。 我在运行程序以通
在我的一个项目中,我最近进行了重构并重命名了很多。完成此步骤后,一切正常,所有单元测试都通过了,但是我遇到了以下问题。 当我在VBE中执行“编译”时,确实出现了“用户定义的类型未定义”错误,并出现两种
所以我的 Visual Studio 将 tag1 和 tag2 都声明为未定义,但它们的定义很清楚,我不能根据另一个定义一个吗? #define push 99 #de
在 Excel 2007 中,我有以下非常简单的 VBA 代码: Public Type specType sb As Long End Type Private Sub MyButton_C
我是一名优秀的程序员,十分优秀!