473,412 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Getting a number out of a string

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

Sep 27 '05 #1
5 1596
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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDOY7JJd01MZaTXX0RAnvrAJ9jK6aatByJuCiXXH4bBP iXHf+iegCgiP9h
3rDgupFxC1qWK9czpUayhIo=
=qR27
-----END PGP SIGNATURE-----

Sep 27 '05 #2
what about:
lst = [digit for digit in '06897']
lst
['0', '6', '8', '9', '7']

Claudio

<ss*******@aol.com> schrieb im Newsbeitrag
news:11**********************@g47g2000cwa.googlegr oups.com... 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

Sep 27 '05 #3
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")
Sep 27 '05 #4
Thanks all! This is just what I needed.

Sep 27 '05 #5
On Tue, 27 Sep 2005 20:28:53 +0000, 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.

Sep 27 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
1
by: pukya78 | last post by:
Hi, I am trying to get the current file and the line number which is getting executed. I used: MessageBox.Show(New StackTrace(New StackFrame(True)).GetFrame(0).GetFileLineNumber) which gives me...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
1
by: biznitchil | last post by:
it is a bit jacked up, but copy and paste it into an IDE(i use jGRASP) plz help me...it worked just fine before I added the menu..you can e-mail me if you have any <Removed> import java.util.*; ...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
13
by: jcato77 | last post by:
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
5
by: tshad | last post by:
I have the following class in my VS 2008 project that has a namespace of MyFunctions. ********************************* Imports System Imports System.Text.RegularExpressions Namespace...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.