How to use range() without argument

In this exercise I did the code posted below. The question is: how can I do infinity range. For ex from 0 (start), to infinity -1 (stop)?
When I put empty space like: range(0, , 5) then error occurs. I’d like to use endless range so the code will be the most universal.

list_1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def mult_five(list_x):
    result_list = []
    for n in list_x:
        for r in range(0, 10000000, 5):
            if n == r:
                result_list.append(n)
    return result_list

Interesting but intuitively I would say: if you make an infinite loop and run it, you will run in big problems ! It will never end…

2 Likes

I forgot about it. Thank you :slight_smile:

I’ve found solution that satisfy me :sunglasses:

list_1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def mult_five(list_x):
    
    result_list = []
    end_index = len(list_x) + 1
    
    for n in list_x:
        for r in range(0, end_index, 5):
            if n == r:
                result_list.append(n)
                
    return result_list
1 Like

Note that in terms of generalization, you will have a problem if I am not wrong if end_index is not a multiple of 5 !
Didn’t check it but the range function will return an error, no?

Edit : it doesn’t return an error so it’s OK.

1 Like