here can depend on call patternsas well as changes and optimizations in python itself recent python releases have sped up the simple for loop statementfor example on some codethoughlist comprehensions are still substantially faster than for loops and even faster than mapthough map can still win when the alternatives must apply function callbuiltin functions or otherwise at least until this story changes arbitrarily-to time these alternatives yourselfsee tools in the standard library' time module or in the newer timeit module added in release or stay tuned for the extended coverage of both of these in the next where we'll prove the prior paragraph' claims why you will carelist comprehensions and map here are some more realistic examples of list comprehensions and map in action we solved the first with list comprehensions in but we'll revive it here to add map alternatives recall that the file readlines method returns lines with \ end-of-line characters at the ends (the following assumes -line text file in the current directory)open('myfile'readlines(['aaa\ ''bbb\ ''ccc\ 'if you don' want the end-of-line charactersyou can slice them off all the lines in single step with list comprehension or map call (map results are iterables in python xso we must run them through list to display all their results at once)[line rstrip(for line in open('myfile'readlines()['aaa''bbb''ccc'[line rstrip(for line in open('myfile')['aaa''bbb''ccc'list(map((lambda lineline rstrip())open('myfile'))['aaa''bbb''ccc'the last two of these make use of file iteratorsas we saw in this means that you don' need method call to read lines in iteration contexts such as these the map call is slightly longer than the list comprehensionbut neither has to manage result list construction explicitly list comprehension can also be used as sort of column projection operation python' standard sql database api returns query results as sequence of sequences like the following--the list is the tabletuples are rowsand items in tuples are column valueslistoftuple [('bob' 'mgr')('sue' 'dev') for loop could pick up all the values from selected column manuallybut map and list comprehensions can do it in single stepand faster[age for (nameagejobin listoftuple[ comprehensions and generations