Combine integers in list into one integer

478 views Asked by At

this is what I wish for...

INPUT [1,2,3,4,5]

OUTPUT 12345

I've tried this but it didn't work...

l1 = [1,2,3,4,5,6]
print([int(n1) for n1 in str(l1).split() if n1.isdigit()])
1

There are 1 answers

0
Giorgos Myrianthous On

If you want the result to be an integer, the following should do the trick:

int(''.join([str(i) for i in l1]))

If you still want it as a string then simply do

''.join([str(i) for i in l1])