. > Thanks Christian for your links and code!!!! > > > _______________________________________________ > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription > options:http://mail.python.org/mailman/listinfo/tutor > > > Below [1] is how I would write it, which is simply a re-factoring of your > code so it's cleaner and more compact. For calculating execution time you > can use the `timeit` module [2] and for more in-depth analysis you can look > at `profile` [3] and further to the bare-bones `dis` [4]. > > [1] > >>> def splitWord(word, number): > ... x = [] > ... for y in xrange(0, len(word), number): > ... x.append(word[y:y+number]) > ... return x > ... > >>> splitWord('google', 1) > ['g', 'o', 'o', 'g', 'l', 'e'] > > >>> splitWord('google', 2) > ['go', 'og', 'le'] > >>> splitWord('google', 3) > ['goo', 'gle'] > >>> splitWord('google', 4) > ['goog', 'le'] > >>> splitWord('google', 5) > ['googl', 'e'] > >>> splitWord('google', 6) > ['google'] > >>> splitWord('google', 7) > ['google'] > > [2] http://www.doughellmann.com/PyMOTW/timeit/ > [3] http://www.doughellmann.com/PyMOTW/profile/index.html#module-profile > [4] http://www.doughellmann.com/PyMOTW/dis/ > > -- > > Christian Witts > Python Developer > > ** >
-- www.tricksfind.blogspot.com
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor