Getting a number out of a string

2005-09-27 Thread ssmith579
I'm trying to extract single digit number from a string. t[1] = '06897' I want to get the 7, 9,8 6 seperated out to use but can't find a way to split out the single characters. Thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a number out of a string

2005-09-27 Thread jepler
You can index into a string: s = '06897' s[2] '8' You can also turn each character into an integer, in various ways: [int(c) for c in s] [0, 6, 8, 9, 7] map(int, s) [0, 6, 8, 9, 7] Jeff pgpDMq5e3RucB.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a number out of a string

2005-09-27 Thread Claudio Grondi
what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] Claudio [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] I'm trying to extract single digit number from a string. t[1] = '06897' I want to get the 7, 9,8 6 seperated out to use but can't find a

Re: Getting a number out of a string

2005-09-27 Thread Will McGugan
Claudio Grondi wrote: what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] Or.. list('06897') ['0', '6', '8', '9', '7'] Will McGugan -- http://www.willmcgugan.com .join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in jvyy*jvyyzpthtna^pbz) --

Re: Getting a number out of a string

2005-09-27 Thread ssmith579
Thanks all! This is just what I needed. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a number out of a string

2005-09-27 Thread Steven D'Aprano
On Tue, 27 Sep 2005 20:28:53 +, Claudio Grondi wrote: what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] No need to use a list comprehension when this works just as well: py list('06897') ['0', '6', '8', '9', '7'] -- Steven. --