both space usage and delays for results for larger itemsthe set of all permutations is much larger than the simpler scrambler'spermute ('spam'=list(permute ('spam')true len(list(permute ('spam')))len(list(scramble('spam'))( list(scramble('spam')['spam''pams''amsp''mspa'list(permute ('spam')['spam''spma''sapm''samp''smpa''smap''psam''psma''pasm''pams''pmsa''pmas''aspm''asmp''apsm''apms''amsp''amps''mspa''msap''mpsa''mpas''masp''maps'per there are nonrecursive alternatives here toousing explicit stacks or queuesand other sequence orderings are common ( fixed-size subsets and combinations that filter out duplicates of differing order)but these require coding extensions we'll forgo here see the book programming python for more on this themeor experiment further on your own don' abuse generatorseibti generators are somewhat advanced tooland might be better treated as an optional topicbut for the fact that they permeate the python languageespecially in in factthey seem less optional to this book' audience than unicode (which was exiled to part viiias we've seenfundamental built-in tools such as rangemapdictionary keysand even files are now generatorsso you must be familiar with the concept even if you don' write new generators of your own moreoveruser-defined generators are increasingly common in python code that you might come across today--in the python standard libraryfor instance in generalthe same cautions gave for list comprehensions apply here as welldon' complicate your code with user-defined generators if they are not warranted especially for smaller programs and data setsthere may be no good reason to use these tools in such casessimple lists of results will sufficewill be easier to understandwill be garbage-collected automaticallyand may be produced quicker (and they are todaysee the next advanced tools like generators that rely on implicit "magiccan be fun to experiment withbut they have no place in real code that must be used by others except when clearly justified orto quote from python' import this motto againexplicit is better than implicit the acronym for thiseibtiis one of python' core guidelinesand for good reasonthe more explicit your code is about its behaviorthe more likely it is that the next programmer will be able to understand it this applies directly to generatorswhose comprehensions and generations