How do I write the magic
function below?
>>> num = 123 >>> lst = magic(num) >>> >>> print lst, type(lst) [1, 2, 3], <type 'list'>
To convert from double to integer, use the as. integer() method and to check the integer value, use the is. integer() method.
Approach #1 : Using list(set_name) . Typecasting to list can be done by simply using list(set_name) . Using sorted() function will convert the set into list in a defined order. The only drawback of this method is that the elements of the set need to be sortable.
To convert each list item from a string to an integer, use the map function. The map function takes two arguments: A function. In this case the function will be the int function.
You mean this?
num = 1234 lst = [int(i) for i in str(num)]
a = 123456 b = str(a) c = [] for digit in b: c.append (int(digit)) print c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With