range(len(result))
with enumerate(result)
33 except Exception as e:
34 print(str(e), "重试...")
35 result = result0.json()["query"]["pages"]
36 for _ in range(len(result)):37 dataNew.update({result[_]["title"]: int(result[_]["revisions"][0]["timestamp"][:4] + result[_]["revisions"][0]["timestamp"][5:7] + result[_]["revisions"][0]
38 ["timestamp"][8:10] + result[_]["revisions"][0]["timestamp"][11:13] + result[_]["revisions"][0]["timestamp"][14:16] + result[_]["revisions"][0]["timestamp"][17:19])})
39 open("/Users/emmm/Desktop/明日方舟/讨论监视.json",
Using range(len(...))
is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators.
Python has a built-in method enumerate
which adds a counter to an iterable.
Using this, you can access the counter and the value from the iterable at the same time.
It is therefore recommended to replace range(len(...))
with enumerate(...)
.
for index in range(len(mylist)):
...
for index, element in enumerate(mylist):
...