Select Specific Numbers

02-09-2022 02:09 PM
New Contributor

Is there a way to select numbers by a specific number or a script for it? For example, I want to select all numbers that are multiples of 5. How could i do it?

0 Kudos
2 Replies
Esri Contributor

You can just use list comprehension:

multiples = [n for n in range(100) if n % 5 == 0]

That gives you all the multiples of 5 between 0 and 99. You can substitute range(100) with any iterable that contains numbers and 5 with any number you choose. 

MVP Esteemed Contributor

If you want to select all records in a layer that are a multiple of a certain number, say 5, then you can use Select Layer By Attribute/Location and the SQL modulo operator:

MOD(Field, 5) = 0

Note, the implementation of the modulo operator does vary between DBMS, so if MOD doesn't work you can search the internet for the specific modulo syntax for the backend data store you are using.