What is the difference between using range() and a list of values?

The main differences between the two boil down to the difference between greedy and lazy evaluation. With a list, each indexed object takes up some space in memory. Range, however, calculates the next value on the fly, meaning only one object is stored in memory each time. However, this means range has to calculate each successive value, slowing down the processing speed.

LS

Related Python Mentoring answers

All answers ▸

Write a function that checks whether a number is prime or not.


Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


What is the difference between DFS and BFS? Where can I apply each?


Write a python function that takes a string as parameter and returns the character in the string with the most occurrences, along with the number of times this character occurs