Python:列表到整数到单个数字?

标签 python list

如果是整数,假设我有几个列表:

x =  [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]

我希望将此列表转换为单个数字,但单个数字类型仍然是整数,即:

4850775602376340

我一直在使用这段代码来执行这个过程:

num = int(''.join(map(str,x)))

但我一直收到值错误。

此外,如果我的列表包含负整数,我如何将它们转换为绝对值?然后将它们转换为单个数字?

x2 = [['48', '-5', '0'], ['77', '56', '0'], ['23', '76', '-34', '0']]

x2 = 4850775602376340

提前致谢。

最佳答案

>>> int(''.join(reduce(lambda a, b: a + b, x)))
4850775602376340

关于Python:列表到整数到单个数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1914883/

相关文章:

python - Django Rest Framework : allow a serializer field to be created, 但未编辑

html - 在两个 div 中均匀分布列出的元素

python - 无论 Python 中的顺序如何,计算元组列表中唯一元素的数量

python - 如何在 python 2.7 中使用 re.UNICODE?

python - 在 Pandas 中迭代生成列名

python - PysimpleGUI 消息框

python - 在 python 中使用带有嵌套字典的计数器

html - 背景随列表展开

python - 如何删除列表中的项目(如果存在)?

python - 将txt表转换为二维列表