为了账号安全,请及时绑定邮箱和手机立即绑定

如何将整数列表拆分为数字整数列表?

如何将整数列表拆分为数字整数列表?

凤凰求蛊 2023-10-18 21:44:54
考虑清单test_list = [14, 12, 10, 8]我想把它重拍/分成test_list = [1, 4, 1, 2, 1, 0, 8]我想将列表分成单个数字。
查看完整描述

4 回答

?
心有法竹

TA贡献1866条经验 获得超5个赞

像这样?(你想分割整数)

newList = [int(y) for x in test_list for y in list(str(x))]


查看完整回答
反对 回复 2023-10-18
?
翻翻过去那场雪

TA贡献2065条经验 获得超13个赞

有点棘手:

b = [int(digit) for digit in ''.join((str(item) for item in a))]
print(b)

输出:

[1, 4, 1, 2, 1, 0, 8]


查看完整回答
反对 回复 2023-10-18
?
守着一只汪

TA贡献1872条经验 获得超3个赞

您可以使用


@client.command()

@commands.has_permissions(**permission needed**=True)

这将只允许具有特定权限的人执行该命令(错误消息选项)。或者,如果您只想要具有某个角色的人员,您可以使用 if message.author.role.id == **role id**: 或 if ctx.message.author.role.id == **role id**:。这是一个示例代码:


@client.event

async def on_message(message):


    link = ["https://"]

    for word in link:

        if message.content.count(word) > 0:

            if message.author.role.id == 706694479847096381:

                return

            else:

                print(f'{message.author}({message.author.id}) Sent an link')

                await message.delete()

           

此代码允许机器人在发送链接时忽略具有该角色的人员。


查看完整回答
反对 回复 2023-10-18
?
蛊毒传说

TA贡献1895条经验 获得超3个赞

这是一种不使用字符串作为中介的替代方法:


test_list = [14, 12, 10, 8]


output_list = []


for number in test_list:

    if number < 10:

        output_list.append(number)

    else:

        output_list.extend([number // 10, number % 10])            


print(output_list)


查看完整回答
反对 回复 2023-10-18
  • 4 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信