Picking out integers from a non-list variable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Picking out integers from a non-list variable (/thread-7138.html) |
Picking out integers from a non-list variable - AnOrdinaryFolk - Dec-22-2017 Imagine there are two variables: source=123456 selected=[] Is there a way to append the first integer from the variable 'source' into the list variable 'selected'? If not, then how can i separate all the integers in the variable 'source' and append them into the 'selected' list like this: >>>print(selected) >>>['1','2','3','4','5','6'] Thanks for any responses. RE: Picking out integers from a non-list variable - Mekire - Dec-22-2017 >>> source = 123456 >>> list(str(source)) ['1', '2', '3', '4', '5', '6'] >>> str(source)[0] '1' >>> RE: Picking out integers from a non-list variable - squenson - Dec-22-2017 You can transform an integer into a string with str(integer_to_convert_to_string) .You can then iterate through each character of the string. |