print(open('table txt'read() herewe cannot preallocate fixed-length list of sums because the number of columns may vary splitting on whitespace extracts the columnsand float converts to numbersbut fixed-size list won' easily accommodate set of sums (at leastnot without extra code to manage its sizedictionaries are more convenient here because we can use column positions as keys instead of using absolute offsets the following code demonstrates interactively (it' also in file summer py in the examples package)sums {for line in open('table txt')cols [float(colfor col in line split()for posval in enumerate(cols)sums[possums get(pos val for key in sorted(sums)print(key'='sums[key] sums { interestinglymost of this code uses tools added to python over the years--file and dictionary iteratorscomprehensionsdict getand the enumerate and sorted built-ins were not yet formed when python was new for related examplesalso see the tkinter grid examples in for another case of eval table magic at work that table sums logic is variation on this themewhich obtains the number of columns from the first line of data file and tailors its summations for display in gui parsing and unparsing rule strings splitting comes in handy for dividing text into columnsbut it can also be used as more general parsing tool--by splitting more than once on different delimiterswe can pick apart more complex text although such parsing can also be achieved with more powerful toolssuch as the regular expressions we'll meet later in this splitbased parsing is simper to code in quick prototypesand may run faster for instanceexample - demonstrates one way that splitting and joining strings can be used to parse sentences in simple language it is taken from rule-based expert system shell (holmesthat is written in python and included in this book' examples distribution (more on holmes in momentrule strings in holmes take the form"rule if then text and language