Python:将整数列表为单个数字吗? [英] Python: List to ints to a single number?
本文介绍了Python:将整数列表为单个数字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果是整数,我有几个清单:
Say i have a several list if ints:
x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
我希望将此列表转换为单个数字,但是单个数字类型仍然是整数,即:
I want this list to be converted to a single number, but the the single number type is still an integer i.e.:
4850775602376340
我一直在使用以下代码来执行该过程:
i have been using this code to carry out the process:
num = int(''.join(map(str,x)))
但我不断收到值错误.
如果我的列表中包含负整数,我该如何将其转换为绝对值?然后将它们转换为一个数字?
Also if my list contained negative integers how would i convert them to there absolute value? Then convert them to a single number?
x2 = [['48','-5','0'],['77','56', '0'], ['23','76','-34','0']]
x2 = [['48', '-5', '0'], ['77', '56', '0'], ['23', '76', '-34', '0']]
x2 = 4850775602376340
x2 = 4850775602376340
提前谢谢.
推荐答案
它是列表的列表,所以
num = int(''.join(''.join(l) for l in lists))
或
def flatten( nested ):
for inner in nested:
for x in inner:
yield x
num = ''.join(flatten(lists))
这篇关于Python:将整数列表为单个数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文