simple question
John Machin
sjmachin at lexicon.net
Sat Mar 23 16:20:11 EST 2002
"Terry Reedy" <tejarex at yahoo.com> wrote in message news:<qh1n8.45972$2q2.4038976 at bin4.nnrp.aus1.giganews.com>...
> "Christopher Palmer" <ctp at ctpdesign.com> wrote in message
> news:mailman.1016868517.25439.python-list at python.org...
>
> > Let's say I have a variable called a
>
> Actually, you have a name 'a'.
>
> > and a contains an integer, say 4522
>
> and the name is bound to an int, conventionally written 4522.
>
> > and I want 4, 5, 2, and 2 to be items in a list instead of an
> integer...
>
> Do you want the list to contain 4 ints (answer given by Johann as:
> map(int, str(a))
> ) or 4 digits:
> ''.split(str(a))
> ?
>
> Terry J. Reedy
I see no 4 digits here. Following are some results of actually RUNNING
some code at the Python command line (version 2.2, Win32):
OP's sample input:
>>> a = 4522
Your suggestion:
>>> ''.split(str(a))
['']
What you probably meant:
>>> str(a).split('')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: empty separator
One possible working solution:
>>> list(str(a))
['4', '5', '2', '2']
More information about the Python-list
mailing list