• bob_lemon@feddit.org
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 months ago
    import re
    
    def is_even(i: int) -> bool:
        return re.match(r"-?\d*[02468]$", str(i)) is not None
    
    • lime!@feddit.nu
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months ago

      i was gonna suggest the classic

      re.match(r"^(..)\1*$", "0" * abs(i)) is not None
      
    • istdaslol@feddit.org
      link
      fedilink
      arrow-up
      1
      ·
      4 months ago

      Not all ARM CPUs support mod operations. It’s better to use bit operations. Check if the last bit is set. If set it’s odd else it’s even.