On Wed, 12 Dec 2007 10:38:56 -0500, Calvin Spealman wrote:
> I still hold my vote that if you need to reverse the "stringification"
> of a list, you shouldn't have stringified the list and lost hold of the
> original list in the first place. That is the solution above all others.
Naturally, but i
Another solution, possibly safer:
>>> from cStringIO import StringIO
>>> import csv
>>> s = "[16, 16, 2, 16, 2, 16, 8, 16]"
>>> sf = StringIO(s.strip()[1:-1])
>>> list(csv.reader(sf))
[['16', ' 16', ' 2', ' 16', ' 2', ' 16', ' 8', ' 16']]
Bye,
bearophile
--
http://mail.python.org/mailman/listinf
I still hold my vote that if you need to reverse the
"stringification" of a list, you shouldn't have stringified the list
and lost hold of the original list in the first place. That is the
solution above all others.
On Dec 12, 2007, at 10:26 AM, Paul McGuire wrote:
> On Dec 12, 7:25 am, Lee
On Dec 12, 7:25 am, Lee Capps <[EMAIL PROTECTED]> wrote:
> Regular expressions might be a good way to handle this.
>
> import re
>
> s = '[16, 16, 2, 16, 2, 16, 8, 16]'
> get_numbers = re.compile('\d\d*').findall
>
> numbers = [int(x) for x in get_numbers(s)]
>
Isn't '\d\d*' the same as '\d+' ?
A