gpt4 book ai didi

python - 如何更改列表中项目的分组?

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:37 26 4
gpt4 key购买 nike

所以如果我有这样一个列表:

x = [0,1,2,3,4,5,6,7,8,9]

我如何将这个列表转换成这样的:

x = [01,23,45,67,89]

我该怎么做?

我知道内置的 zip 功能,但我不想要一个 元组,我想要将 2 个数字组合成 1 个。

最佳答案

你可以试试这个:

x = [0,1,2,3,4,5,6,7,8,9]

x = map(str, x)

new_list = map(int, [x[i]+x[i+1] for i in range(0, len(x)-1, 2)])

关于python - 如何更改列表中项目的分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44356418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com