Hi,
I am trying to extract all numbers and string from a long string and store them in a array, but the my expressing always split a decimal number and make all integer numbers. Codes like following
# -*- coding: cp1252 -*-
import re
DATA = r"26°48'18.3431\"E 39°36'6.979\"N"
print re.findall(r"[\d+\w+]+", DATA)
it returns ['26', '48', '18', '3431', 'E', '39', '36', '6', '979', 'N']
I want the statement returns ['26', '48', '18.3431', 'E', '39', '36', '6.979', 'N']
Can anyone help?
Thanks.
Dave
Solved! Go to Solution.
I am using utf-8 adjust if necessary... I will show it verbosely so you can see what I did... consolidate if needed
>>> nogood = ["°", "'", '\\','"'] >>> good = ''.join([ [i, ' '][i in nogood] for i in DATA]) >>> asList = [ i for i in good.split(" ") if i!='' ] >>> good '26 48 18.3431 E 39 36 6.979 N' >>> asList ['26', '48', '18.3431', 'E', '39', '36', '6.979', 'N'] >>>
I am using utf-8 adjust if necessary... I will show it verbosely so you can see what I did... consolidate if needed
>>> nogood = ["°", "'", '\\','"'] >>> good = ''.join([ [i, ' '][i in nogood] for i in DATA]) >>> asList = [ i for i in good.split(" ") if i!='' ] >>> good '26 48 18.3431 E 39 36 6.979 N' >>> asList ['26', '48', '18.3431', 'E', '39', '36', '6.979', 'N'] >>>
you are amazing! , Dan. That works perfectly for me. Thanks.
Dave
Hey Dave, since Dan's suggestion worked for you, how about marking the thread as answered?
I guess, I will let one of the other moderators mark my answer correct then.... sigh,