powexpr = to time the relative speeds of python and dictionary comprehensions and equivalent for loops interactivelyyou can run session like the following it appears that the two are roughly the same in this regard under python unlike list comprehensionsthoughmanual loops are slightly faster than dictionary comprehensions today (though the difference isn' exactly earth-shattering--at the end we save half second when making dictionaries of , , items eachagainrather than taking these results as gospel you should investigate further on your ownon your computer and with your pythonc:\codec:\python \python def dictcomp( )return {ii for in range( )def dictloop( )new {for in range( )new[ii return new dictcomp( { dictloop( { from timer import totalbestof bestof(dictcomp )[ , -item dict bestof(dictloop )[ bestof(dictcomp )[ , -items slower bestof(dictloop )[ bestof(dictcomp )[ of -items time bestof(dictloop )[ total(dictcomp _reps= )[ total to make -item dicts total(dictloop _reps= )[ recursive functions coded this function as followsa simple rangecomprehensionor map will do the job here as wellbut recursion is useful enough to experiment with here (print is function in onlyunless you import it from __future__ or code your own equivalent) appendix dsolutions to end-of-part exercises