so I have to create a List of a big range and am trying to accomplish this with list(range(number1, number2))
and the numbers number1
and number2
can have a big difference, for example 235 and 4323246376. Now, this takes a long time to process. Can this process be sped up?
CodePudding user response:
If you're only looking to use the list as a filter to count items in another list, you should not be using a range at all.
For example:
count = numpy.sum(theList >= 235) - numpy.sum(theList >= 4323246376)
CodePudding user response:
What use case are you going to achieve with this?
In case you are going to use this list once, don't typecast the range object into a list. When you typecast the range object into a list, It stores all the numbers in a list which costs you memory. You can just iterate over the range object.