simple question

Tim Hammerquist tim at vegeta.ath.cx
Sat Mar 23 19:51:14 EST 2002


Christopher Palmer graced us by uttering:
> Let's say I have a variable called a
> 
> and a contains an integer, say 4522
> 
> and I want 4, 5, 2, and 2 to be items in a list instead of an integer...
> 
> I know it must be dirt simple, but nothing I have tried so far has worked.

Actually, not as simple as it might be, but here's what I came up with:

    >>> i = 4522
    >>> l = [x for x in str(i)
    >>> l
    ['4', '5', '2', '2']
    >>> 

> Thanks in advance,
> CTP

HTH
Tim Hammerquist
-- 
I would feel infinitely more comfortable in your presence if you would agree
to treat Gravity as a Law, rather than one of a number of suggested options.
    -- Barnabas, The Sandman



More information about the Python-list mailing list