1
xiaolinjia 2020-09-11 11:30:01 +08:00 3
enumerate
|
2
jmc891205 2020-09-11 12:20:06 +08:00
for i in range(len(list)-1)
|
3
TimePPT 2020-09-11 12:24:47 +08:00 via Android
enumerate +1
|
4
datou 2020-09-11 12:32:48 +08:00
list.index()
|
5
QGabriel OP 具体怎么写啊~以上的方法都试了好像不行啊
|
7
qW7bo2FbzbC0 2020-09-11 13:47:26 +08:00
enumerate
|
8
1018ji 2020-09-11 13:48:54 +08:00
你只比较 0 和 1 我咋感觉这需求这么诡异
|
9
xiaolinjia 2020-09-11 13:56:47 +08:00
|
10
xdnauly 2020-09-11 14:08:09 +08:00
list[0].get("a") == list[1].get("a")
#还有 list[0]['a'] == list[1]['a'] 不是可以直接比较啊,没有太看懂你的问题 |
11
QGabriel OP @xiaolinjia 谢谢!
|
12
TenaxTsi 2020-09-11 14:53:19 +08:00
@xiaolinjia 这工具不错。
|
13
QGabriel OP @xiaolinjia list 的类型是 pymongo.cursor.Cursor db[index + 1]['a'] 就提示错误了
----- Traceback (most recent call last): File "C:/python/t.py", line 10, in <module> if (item['code'] == db[index + 1]['code']): File "C:\python\venv\lib\site-packages\pymongo\cursor.py", line 612, in __getitem__ self.__check_okay_to_chain() File "C:\python\venv\lib\site-packages\pymongo\cursor.py", line 401, in __check_okay_to_chain raise InvalidOperation("cannot set options after executing query") pymongo.errors.InvalidOperation: cannot set options after executing query |
14
xiaolinjia 2020-09-11 16:14:37 +08:00
@QGabriel 试试把他转成 list(db),然后再操作。
|
15
biglazycat 2020-09-11 21:18:26 +08:00
list = [{'a': 1},{'a':2},{'a':3}]
for index, mem in enumerate(list): if index < len(list) - 1: print(mem['a']) print(list[index + 1]['a']) |
16
biglazycat 2020-09-11 21:19:31 +08:00
@xiaolinjia 装您的代码抄了一下。请问代码是怎么传到 ubuntu 上的?
|