letters = ['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)
假设这是我的清单.哪里for i, letter in enumerate(letters)会:
0, a
1, b
2, c
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它向后枚举,如:
2, a
1, b
0, c
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写干净简洁的代码,并且在很多代码中,我看到有时候我看到人们的代码不一致.我问的是,有没有这样的实例
print("Cars on the road: " + cars)
比这更合适
print("Cars on the road: {}".format(cars))
或者只是一个偏好的问题?
首先我要说的是我对 Python 很陌生。我一直在使用 discord.py 和 Beautiful Soup 4 构建一个 Discord 机器人。这就是我现在的位置:
@commands.command(hidden=True)
async def roster(self):
"""Gets a list of CD's members"""
url = "http://www.clandestine.pw/roster.html"
async with aiohttp.get(url) as response:
soupObject = BeautifulSoup(await response.text(), "html.parser")
try:
text = soupObject.find_all("font", attrs={'size': '4'})
await self.bot.say(text)
except:
await self.bot.say("Not found!")
Run Code Online (Sandbox Code Playgroud)
现在,我尝试使用get_text()多种不同的方式从这段代码中删除括号和 HTML 标签,但每次都会抛出错误。我如何才能实现这一目标或将这些数据输出到数组或列表中,然后只打印纯文本?
这是一个示例字典,colors:
{
"Red" : {
"members" : {
"153950039532134112" : {
"rank" : 1,
"score" : 43,
"time" : 1530513303
}
},
"rank" : 2,
"score" : 43
},
"Blue" : {
"members" : {
"273493248051539968" : {
"rank" : 1,
"score" : 849,
"time" : 1530514923
},
"277645262486011904" : {
"rank" : 2,
"score" : 312,
"time" : 1530513964
},
"281784064714487810" : {
"rank" : 3,
"score" : 235,
"time" : 1530514147
}
},
"rank" : 1, …Run Code Online (Sandbox Code Playgroud)