I’ve got a very long ( 1000 digit ) number.
I want to convert it into a list , how would you go about it since :
list(n)
TypeError: ‘long’ object is not
iterable
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not exactly clear what you’re asking for, but if what you want is to iterate over the digits, just convert it to a string:
You can iterate over a string as if it were a list.
If you really want a true list (only reason I can think of is you want to modify digits), you can do:
(In the event someone comes along looking for a way to convert an 1000-digit integer into a list of bytes, the answer is… normally don’t, it’s not really meaningful in most contexts (numbers that big aren’t stored/manipulated as typical native data types). If you need to get it into a packed binary form, look into NumPy, which you should probably be using anyway if you’re routinely dealing with numbers this large.
If you’ve got a more typical number (e.g. 8, 16, 32 or 64 bits), check out the included struct module.)