【发布时间】:2023-02-20 23:03:08
【问题描述】:
import re
import requests
t=[]
u = []
n = []
k = []
exclude_banned = True
with open("u.txt", "r") as f:
h = f.readlines()[0:100]
for sub in h:
t.append(re.sub('\n', '', sub))
print(type(t))
print(t)
r = requests.post('https://users.roblox.com/v1/usernames/users', json={'usernames': t, 'excludeBannedUsers': exclude_banned})
print(r.json())
y = r.json()['data']
u.extend([f['id'] for f in y])
n.extend([f['name'] for f in y])
k.append(f'{u[0]}:{n[0]}\n{u[1]}:{n[1]}')
print(k)
我想将列表u 中的所有变量加入列表n,就像它们在列表k 中的加入方式一样。我将如何大规模地做到这一点?
我尝试了列表k 中的方法,但那会非常耗时,现在所有列表的长度总是相同的。
文件中的文本是这个https://gist.githubusercontent.com/deekayen/4148741/raw/98d35708fa344717d8eee15d11987de6c8e26d7d/1-1000.txt
【问题讨论】:
-
嗨,对不起,我对 python 很不好,您必须向我展示一个工作示例,以便我理解 .extend 方法是什么,谢谢!
-
这回答了你的问题了吗? How do I concatenate two lists in Python?
-
如果您分享来自
u.txt的示例、y中的 json/对象以及所需的结果,将会很有帮助。