By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 1,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

Parsing numbers separated with different number of blanks

P: 1
Hello,

I wonder how I can parsing and recognize the numbers below.
The problem is.. it has blanks between numbers but the number of blank is not consistent due to the sign and digit of number are taken as one column.
Perhaps, I have to first change the blanks to tab?

-4 0 -7 -3 -1 0

Thanks in advance.

Y.
Jul 29 '13 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
Assuming your data is a string:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "-4 0 -7 -3 -1 0"
  2. >>> data = [int(x) for x in s.split()]
  3. >>> data
  4. [-4, 0, -7, -3, -1, 0]
  5. >>> 
Jul 29 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.