gracefully handling broken pipes (was Re: Converting a string toan array?)

Fredrik Lundh fredrik at pythonware.com
Thu Jan 12 18:53:32 EST 2006


Tim Chase wrote:

> >  >>> import random
> >  >>> s = "abcdefg"
> >  >>> data = list(s)
> >  >>> random.shuffle(data)
> >  >>> "".join(data)
> > 'bfegacd'
> >
> > fit you better?
>
> Excellent!  Thanks.  I kept trying to find something like an
> array() function.  Too many languages, too little depth.

>>> from array import array
>>> a = array('c', "abcdefgh")
>>> a
array('c', 'abcdefgh')
>>> import random
>>> random.shuffle(a)
>>> a
array('c', 'gfecdabh')
>>> a.tostring()
'gfecdabh'

</F>






More information about the Python-list mailing list