《Cracking the Coding Interview》——第17章:普通题——题目10

2014-04-28 23:54

题目:XML文件的冗余度很大,主要在于尖括号里的字段名。按照书上给定的方式进行压缩。

解法:这题我居然忘做了,只写了一句话的注解。用python能够相对方便地实现,因为有直接的XML工具可以调用。书上的那种要求应该是符合前序遍历规则。

代码:

1 # 17.10 Parse an XML file, and try to save some space by mapping every item name to an integer index.
2 # Answer:
3 #    Preordere traversal of an element tree, maybe ElementTree will be a good tool.
原文地址:https://www.cnblogs.com/zhuli19901106/p/3698296.html