“分裂” RLE (groupby) 的输出取决于定义的值(用于分割 RLE 的“字符”)
考虑“字符串”(将其视为数字数组)
0 0 1 8 8 8 1 0
RLE(“groupby”)是:
[(0,2), (1, 1), (8,3), (1, 1), (0, 1)]
然后,我们用前面元素的游程长度之和来丰富上述 RLE。
因此,上述内容的丰富版本变为:
[(0, (0,2)), (0+2, (1, 1)), (0+2+1, (8,3)), (0+1+2+3, (1, 1)), (0+1+2+3+1, (0, 1))]
The "string" split on 1:
0 0 , 8 8 8 , 0
RLE split on 1
[(0,2)] , [(8,3)] , [(0, 1)]
The "string" split on 8:
0 0 1 , , , 1 0
RLE split on 8
[(0,2), (1, 1)] , , , [(1, 1), (0, 1)]
注意:在我的示例中,我引用了“RLE split on Z”列出而不丰富它们。事实并非如此。我把它们留下来以减少混乱。例如,“RLE split on 1”实际上应该被视为:
[(0, (0,2))] , [(0+2+1, (8,3))] , [(0+1+2+3+1, (0, 1)]
如何在 Z 上实现此“RLE split”(= 1, 8;在本例中)
可以留空数组(分割后)。
也许是一个聪明的列表比较? (使用嵌套有附加的 for 循环似乎更容易解决)
Consider the "string" ( treat it as an array of digits )
0 0 1 8 8 8 1 0
The RLE ( "groupby" ) is:
[(0,2), (1, 1), (8,3), (1, 1), (0, 1)]
We then enrich the above RLE with the sum of the run lengths of the previous elements.
Hence, the enriched version of the above becomes:
[(0, (0,2)), (0+2, (1, 1)), (0+2+1, (8,3)), (0+1+2+3, (1, 1)), (0+1+2+3+1, (0, 1))]
The "string" split on 1:
0 0 , 8 8 8 , 0
RLE split on 1
[(0,2)] , [(8,3)] , [(0, 1)]
The "string" split on 8:
0 0 1 , , , 1 0
RLE split on 8
[(0,2), (1, 1)] , , , [(1, 1), (0, 1)]
Note : In my examples, I have cited the "RLE split on Z" lists without enriching them. This would not be so. I left them out to reduce clutter. For example, the "RLE split on 1" should really be treated as:
[(0, (0,2))] , [(0+2+1, (8,3))] , [(0+1+2+3+1, (0, 1)]
How can I achieve this "RLE split" on Z ( = 1, 8; in this case )
It's fine to leave out empty arrays ( after split ).
Perhaps a clever list comp.? ( it seems a little easier to solve with a for loop with an append nested within )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了展示如何使用,我强烈建议您不要使用这种
“优雅”的丑陋方式:
Just for show the way how, I strongly advise you not to use this
"elegant" ugly way: