Converting a string to an array?
Grant Edwards
grante at visi.com
Thu Jan 12 18:15:02 EST 2006
On 2006-01-12, Ron Griswold <RGriswold at Rioting.com> wrote:
>> This lacks the beauty of most python code, and clearly feels like
>> there's somethign I'm missing. Is there some method or function
>> I've overlooked that would convert a string to an array with less
>> song-and-dance? Thanks,
>
>> import random
>> s = "abcdefg"
>> a = []
>> a.extend(s)
>> random.shuffle(a)
>> s = "".join(a)
>
> Does this do what you are looking for?
>
>>>> s = 'abcdefg';
>>>> a = [];
>>>> a += s;
>>>> a;
> ['a', 'b', 'c', 'd', 'e', 'f', 'g']
That's a bit round-about:
>>> list('abcdefg')
['a', 'b', 'c', 'd', 'e', 'f', 'g']
--
Grant Edwards grante Yow! Yow! Am I cleansed
at yet?!
visi.com
More information about the Python-list
mailing list