I am using the following code:-
my_list = range(1,99)
list_Odd_Numbers = list(filter(lambda varX: varX % 2 == 1,my_list))
print(list_Odd_Numbers)
I want random and infinite loop
I am using the following code:-
my_list = range(1,99)
list_Odd_Numbers = list(filter(lambda varX: varX % 2 == 1,my_list))
print(list_Odd_Numbers)
I want random and infinite loop
Just import random and then:
import random
my_list = range(1,99)
list_Odd_Numbers = list(filter(lambda varX: varX % 2 == 1,my_list))
while True: # Not recommended, but since you asked for infinite loop...
x = random.choice(list_Odd_Numbers) # Pick randomly one number from the list.
print(x) # or do whatever you need to with this random pick.
from random import randint
random_odd_numbers = (val for val in iter(lambda: randint(1, 99), 0) if val % 2 != 0)
for number in random_odd_numbers:
print(number)
Prints:
...
99
81
57
85
87
95
49
...and so on.
Here is simple solution, don't need to filter anything
2*random.randint(0,49)+1
If you need 100 numbers in a list
[2*random.randint(0,49)+1 for _ in range(0,100)]
UPDATE
Actually, there is a function in standard Python which does the job
random.randrange(1, 100, 2)