0

I am writing a program that relays the number of integers in every 10,000,000 integers. There are over 1 billion integers in the file. The output needs to go to a different file. Is there a function I can use that will loop through every 10,000,000 integers for me rather than typing count_numbers(0, 10000001) count_numbers(1000000, 20000001) etc. every time? I currently have the following code:

f = open("countoutput.txt", "w")
def count_numbers(x, y):
    count = 0
    for line in filename:    
        for number in line.split():
            if int(number) > x and int(number) < y:
                count += 1
    f.write(str(count))
Ellie
  • 117
  • 2
  • 8

1 Answers1

0

There's likely a terser way to do this, but here's what I have off the top of my head

for low,high in zip(range(0, 10**10, 10**7), range(10**7 +1, 10**10, 10**7)):
    count_numbers(low, high)
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241