关于空白填充的成功结果的第2部分 [英] Part 2 of a successful outcome regarding white-space filling

查看:81
本文介绍了关于空白填充的成功结果的第2部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的第一个问题已正确回答.作为参考,您可以在这里...

So, my first question was answered correctly. For reference you can go here...

如何用空白填充信息,而其余部分保持不变?

简而言之,我需要这个...

In short, I needed this...

POLYGON_POINT -79.750000000217,42.017498354525,0
POLYGON_POINT -79.750000000217,42.016478251402,0
POLYGON_POINT -79.750598748133,42.017193264943,0
POLYGON_POINT -79.750000000217,42.017498354525,0


POLYGON_POINT -79.750000000217,42.085882815878,0
POLYGON_POINT -79.750000000217,42.082008734634,0
POLYGON_POINT -79.751045507507,42.082126409633,0
POLYGON_POINT -79.750281907508,42.083166574215,0
POLYGON_POINT -79.750781149174,42.084212672130,0
POLYGON_POINT -79.750000000217,42.085882815878,0

要成为这个...

BEGIN_POLYGON
POLYGON_POINT -79.750000000217,42.017498354525,0
POLYGON_POINT -79.750000000217,42.016478251402,0
POLYGON_POINT -79.750598748133,42.017193264943,0
POLYGON_POINT -79.750000000217,42.017498354525,0
END_POLY
BEGIN_POLYGON
POLYGON_POINT -79.750000000217,42.085882815878,0
POLYGON_POINT -79.750000000217,42.082008734634,0
POLYGON_POINT -79.751045507507,42.082126409633,0
POLYGON_POINT -79.750281907508,42.083166574215,0
POLYGON_POINT -79.750781149174,42.084212672130,0
POLYGON_POINT -79.750000000217,42.085882815878,0
END_POLY

通过python脚本成功完成.现在,我发现我需要删除重复的行,特别是每个块中的最后一行.那条线关闭了多边形,但是建筑批处理给出了错误,因为它自己关闭了多边形.基本上,我需要它成为一切的结尾...

Which was succesfully accomplished with a python script. Now I have found that I need to remove duplicate lines, specifically the last line from each block. That line closes the polygon but the building batch gives an error because it closes the polygon on it's own. Basically I need it to be this at the end of it all...

BEGIN_POLYGON
POLYGON_POINT -79.750000000217,42.017498354525,0
POLYGON_POINT -79.750000000217,42.016478251402,0
POLYGON_POINT -79.750598748133,42.017193264943,0
END_POLY
BEGIN_POLYGON
POLYGON_POINT -79.750000000217,42.085882815878,0
POLYGON_POINT -79.750000000217,42.082008734634,0
POLYGON_POINT -79.751045507507,42.082126409633,0
POLYGON_POINT -79.750281907508,42.083166574215,0
POLYGON_POINT -79.750781149174,42.084212672130,0
END_POLY

有3,415,978行要经过.每隔一个重复的去除器将占用空白和所有措辞.嗯

and there are 3,415,978 lines to go through. Every other duplicate remover takes away the white space and all the wording. Hmmm

推荐答案

如果您不希望重复数据,则可以将列表转换为set,然后转换为list(从另一个问题中获取@Jean-FrançoisFabre代码一点修改):

if you don't want duplicated data, you can trasform the list into set, then into list (taking the @Jean-François Fabre code from the other question an little modific):

import itertools, collections

with open("file.txt") as f, open("fileout.txt","w") as fw:
    fw.writelines(itertools.chain.from_iterable([["BEGIN_POLYGON\n"]+list(collections.OrderedDict.fromkeys(v).keys())+["END_POLYGON\n"] for k,v in itertools.groupby(f,key = lambda l : bool(l.strip())) if k]))

如您所见,如果您这样做:

as you can see, if you do:

print(list(collections.OrderedDict.fromkeys([1,1,1,1,1,1,2,2,2,2,5,3,3,3,3,3]).keys()))

它将是-> [1, 2, 5, 3],并且您将保留订单

it will be -> [1, 2, 5, 3] and yo preserve the order

这篇关于关于空白填充的成功结果的第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆