我有一个像这样的数据文件。在
HETATM 1 H10 XSHQ 0 10.139 2.231 0.091 1.00 0.00 H
HETATM 2 N1 XSHQ 0 9.641 1.386 -0.104 1.00 0.00 N
HETATM 3 H9 XSHQ 0 9.773 1.133 -1.063 1.00 0.00 H
HETATM 4 C1 XSHQ 0 8.245 1.531 0.230 1.00 0.00 H
其中XYZ坐标在第6、7、8列和最后一列中,与点相关联的字母在最后一列中。我想确定在最后一列有字母H的点之间的距离。我该怎么做?我知道这是我执行该操作所需的代码,但我不清楚如何使用第6、7和8列中的值,而且只适用于最后一列是H的情况:
^{pr2}$
当然,@smonener的答案已经是正确的,使用
OrderedDict
这样的数据结构是个好主意,但是如果只想使用标准方法,可以尝试:我使用regexp来提取日期,然后根据规则过滤它们。在
演示代码如下:
使用生成器表达式的简单解决方案
因为
以及} ,因为您需要计算数据集中每对有趣的点的距离。在
itertools
标准库模块中的^{相关问题 更多 >
编程相关推荐