文件解析后逆分组扩展
【问题】
I have a tab-delimited file with three columns (Name Nr1 Nr2) like the following:
ABC 201 215
DEF 301 320
GHI 350 375
I would like to transfer the last file into the following format:
ABC 201 201 #taking the value from the first value from the second column and continue line by line till the second value in the third line as the following
ABC 202 202
ABC 203 203
......and so on till the third column value
ABC 215 215
DEF 301 301 ....and so on till the third column value
DEF 320 320
GHI 350 350
GHI 351 351
GHI 351 351
....
GHI 375 375
is that possible in python?
I would really appreciate your help in this Thanks in advance
【回答】
循环源文件每条记录,从第2个到第3个字段循环当前记录,再合并各组记录。上述算法涉及多层循环,用SPL更简单,只要两行:
A |
|
1 |
=file("d:/file.txt").import() |
2 |
=A1.news(to(#2,#3);A1.#1,~,~) |
A1:读取file.txt文件内容。
A2:针对A1每条记录从第2个到第3个字段循环当前记录,再合并各组记录。