text processing

kib2 kib2 at free.fr
Thu Sep 25 15:22:25 EDT 2008


You can do it with regexps too :

 >------------------------------------------------------------------
import re
to_watch = re.compile(r"(?P<number>\d+)[/](?P<letter>[A-Z]+)")

final_list = to_watch.findall("12560/ABC,12567/BC,123,567,890/JK")

for number,word in final_list :
     print "number:%s -- word: %s"%(number,word)
 >------------------------------------------------------------------

the output is :

number:12560 -- word: ABC
number:12567 -- word: BC
number:890 -- word: JK

See you,

Kib².



More information about the Python-list mailing list