len('abc'[ , , ][ {'spam': }['spam' :\pp \langpython summer py table txt [ summing with zips and comprehensions we'll revisit eval later in this when we explore expression evaluators sometimes this is more than we want--if we can' be sure that the strings that we run this way won' contain malicious codefor instanceit may be necessary to run them with limited machine access or use more restrictive conversion tools consider the following recoding of the summer function (this is in file summer py in the examples package if you care to experiment with it)def summer(numcolsfilename)sums [ numcols for line in open(filename)cols line split(','nums [int(xfor in colsboth zip(sumsnumssums [ for (xyin bothreturn sums use file iterators assume comma-delimited use limited converter avoid nested for loop xzip is an iterable this version uses int for its conversions from strings to support only numbersand not arbitrary and possibly unsafe expressions although the first four lines of this coding are similar to the originalfor variety this version also assumes the data is separated by commas rather than whitespaceand runs list comprehensions and zip to avoid the nested for loop statement this version is also substantially trickier than the original and so might be less desirable from maintenance perspective if its code is confusingtry adding print call statements after each step to trace the results of each operation here is its handiworkc:\pp \langtype table txt , , , , , , , , , , , , , , , , :\pp \langpython summer py table txt [ summing with dictionaries the summer logic so far worksbut it can be even more general-by making the column numbers key of dictionary rather than an offset in listwe can remove the need to pass in number-columns value altogether besides allowing us to associate meaningful labels with data rather than numeric positionsdictionaries are often more flexible than lists in generalespecially when there isn' fixed size to our problem for instancesuppose you need to sum up columns of data stored in text file where the number of columns is not known or fixedstring method utilities