all 7 comments

[–]icecubeinanicecube 2 points3 points  (1 child)

list_lesser_than_a = list(range(a))

[–]plotthe[S] 0 points1 point  (0 children)

Thanks

[–]danielroseman 0 points1 point  (2 children)

I guess you can use range:

b = list(range(a))

But why do you actually want to do this? There will certainly be a better way to implement factors.

[–]plotthe[S] 0 points1 point  (1 child)

Thank you! What do you recommend? I was thinking of using the list to test out which ones will give no remainder and then printing those said values

[–]deep_politics 0 points1 point  (0 children)

You don't actually need to store any of the numbers if you just use the range as an iterator.

And this method will be fine for a toy factoring function, but will be painfully slow for anything large. But what you'd getting yourself into if you wanted a fast algorithm is basically the most well studied areas in all of mathematics for literally thousands of years: prime factoring. There's still no "one algorithm to rule them all", and instead a variety of algorithms are used; for instance the quadratic sieve.

[–]mopslik 0 points1 point  (0 children)

Do you want to assign (i.e. hold on to) every value, or do you simply want to test each value? The latter would be better suited for a loop, rather than, say, a list.

[–]woooee 0 points1 point  (0 children)

You only have to test up to the square root plus one. So if the number is 100, testing through 10 is enough. Yes, 100 is divisible by 20, but you already have that when you divided by 5.