[Tutor] substituting empty line with stuff
Shantanoo Mahajan
shantanoo at gmail.com
Wed Aug 3 18:50:42 CEST 2005
+++ Srinivas Iyyer [02-08-05 14:54 -0700]:
| Hello group:
|
| I have a file (3339203 lines) that looks like this:
|
| (col:1) (col:2) (col:3)
| AD134KL
| XXXXX XXXXX
| Xaaaa Xaaaa
| Xbbbb Xbbbb
|
| AD144KL
| YYYYY YYYYY
| Yaaaa Yaaaa
|
| Now I have to fill the rows in column 1 with their
| designated stuff:
|
| AD134KL
| AD134KL XXXXX XXXXX
| AD134KL Xaaaa Xaaaa
| AD134KL Xbbbb Xbbbb
| AD144KL
| AD144KL YYYYY YYYYY
| AD144KL Yaaaa Yaaaa
|
|
|
| My code:
|
| f1 = open('xx','r')
| meat = f1.readlines()
|
| mind = []
|
| for i in range(len(meat)):
| if meat[i].startswith('AD'):
| mind.append(i)
|
| mind = [0,4]
|
| for i in range(len(mind)):
| k = i+1
| l = mind[i]+1
| j = mind[k]-1
| print l,j
|
| 1 3
|
| Logic: Now I want to substitute 'AD134KL' between 0
| and 4 which is 1,2,and 3. and move on..
|
| After coming to this stage, I lost grip and I do not
| know what to do..
|
| Can experts help me please.
|
| thank you
| srini
|
Maybe...
for x in open('_file_'):
a=x.split()
if len(a) == 1:
b = a[0]
else:
print b,
print x,
Regards,
Shantanoo
More information about the Tutor
mailing list