using lists as queues it is also possible to use list as queuewhere the first element added is the first element retrieved ("first-infirst-out")howeverlists are not efficient for this purpose while appends and pops from the end of list are fastdoing inserts or pops from the beginning of list is slow (because all of the other elements have to be shifted by oneto implement queueuse collections deque which was designed to have fast appends and pops from both ends for examplefrom collections import deque queue deque(["eric""john""michael"]queue append("terry"terry arrives queue append("graham"graham arrives queue popleft(the first to arrive now leaves 'ericqueue popleft(the second to arrive now leaves 'johnqueue remaining queue in order of arrival deque(['michael''terry''graham']list comprehensions list comprehensions provide concise way to create lists common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterableor to create subsequence of those elements that satisfy certain condition for exampleassume we want to create list of squareslikesquares [for in range( )squares append( ** squares [ note that this creates (or overwritesa variable named that still exists after the loop completes we can calculate the list of squares without any side effects usingsquares list(map(lambda xx** range( ))orequivalentlysquares [ ** for in range( )which is more concise and readable list comprehension consists of brackets containing an expression followed by for clausethen zero or more for or if clauses the result will be new list resulting from evaluating the expression in the context of the for and if clauses which follow it for examplethis listcomp combines the elements of two lists if they are not equal[(xyfor in [ , , for in [ , , if ! [( )( )( )( )( )( )( )and it' equivalent to more on lists