[Tutor] Read and write list on I file

jarod_v6 at libero.it jarod_v6 at libero.it
Sat Jan 26 10:21:24 CET 2013


HI there!!!
I have a file like this:

12345-2 ppppppppppppppppppppppppppppppppppppppppppp
12389-4

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
...

I want to read  this file and organize in different way: The second number
present  after "-" mean the times are ripetuted the elements..so in the 
example
In the end I want to  have this result

12345-1 ppppppppppppppppppppppppppppppppppppppppppp
12345-2 ppppppppppppppppppppppppppppppppppppppppppp
12389-1

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
12389-2

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
12389-3

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
12389-4

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Someone have a suggestion how to do this simple task.. I write some code but
don't do all the think I want.

import re

f = open("file.txt","r")

for item in f:
     if re.match(r'['0-9]',item):
                          line=iteme.strip.split("\t")
                          num = line[0].split("-")
                          key = num[0]
                          vl = in(num[1])
                          for i in range(1,vl):
                                             ....

       else:
           print all line"





thanks in advance for any help!



More information about the Tutor mailing list