of magnitude slower in cpythonthough these results vary in pypydef rev ( )if len( = return elsereturn [- rev ( [:- ]recursive slower in cpython today def rev ( )return 'join(reversed( )nonrecursive iterablesimplerfaster def rev ( )return [::- even better?sequence reversal by slice part vmodules and packages see "test your knowledgepart exerciseson page in for the exercises import basics when you're doneyour file (mymod pyand interaction should look similar to the followingremember that python can read whole file into list of line stringsand the len built-in returns the lengths of strings and listsdef countlines(name)file open(namereturn len(file readlines()def countchars(name)return len(open(nameread()def test(name)return countlines(name)countchars(nameor pass file object or return dictionary python import mymod mymod test('mymod py'( your counts may varyas mine may or may not include comments and an extra line at the end note that these functions load the entire file in memory all at onceso they won' work for pathologically large files too big for your machine' memory to be more robustyou could read line by line with iterators instead and count as you godef countlines(name)tot for line in open(name)tot + return tot def countchars(name)tot part vmodules and packages