I made a list of the following:
digits = list(str(number)) How to return the original number from the list?
I made a list of the following:
digits = list(str(number)) How to return the original number from the list?
Like this:
number = 15 number = list(str(number)) print(type(number)) #печатает <class 'list'> num = "" for n in number: num += n num = int(num) print(num, type(num)) #печатает 15 <class 'int'> It is possible so:
number = int(''.join(number)) Here ''.join(number) combines the list into a string, and int() makes a number from a string.
join combines (produces contact) of all the elements of the sequence passed to it as an argument, inserting the string for which the method was called between the elements. That is, imagine that we have a list lst = ["foo", "bar", "buzz"] , then if we do this in '+'.join(lst) , then 'foo+bar+buzz' will be printed. - Flowneeereduce(lambda number, digit: number*10 + digit, map(int, digits)) - jfsSource: https://ru.stackoverflow.com/questions/580280/
All Articles