[ : [: print(lend='slice so any sequence type works [ [ [ alternativelyas we saw in we get the same results by moving an entire front section to the endthough the order of the results varies slightlyfor in range(len( )) [ : [:iprint(xend='for positions rear part front part (same effectspam pams amsp mspa simple functions as isthis code works on specific named variables only to generalizewe can turn it into simple function to work on any object passed to its argument and return resultsince the first of these exhibits the classic list comprehension patternwe can save some work by coding it as such in the seconddef scramble(seq)res [for in range(len(seq))res append(seq[ :seq[: ]return res scramble('spam'['spam''pams''amsp''mspa'def scramble(seq)return [seq[ :seq[:ifor in range(len(seq))scramble('spam'['spam''pams''amsp''mspa'for in scramble(( ))print(xend='( ( ( we could use recursion here as wellbut it' probably overkill in this context generator functions the preceding section' simple approach worksbut must build an entire result list in memory all at once (not great on memory usage if it' massive)and requires the caller to wait until the entire list is complete (less than ideal if this takes substantial amount of timewe can do better on both fronts by translating this to generator function that yields one result at timeusing either coding schemedef scramble(seq)for in range(len(seq)) comprehensions and generations