文件解析后逆分组扩展

【问题】

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个字段循环当前记录,再合并各组记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值