Sha256: a72aa34c8e3b64aa29802a525f38e2bf6dce4e8da068e62b26e4f583b89bcb44

Contents?: true

Size: 345 Bytes

Versions: 125

Compression:

Stored size: 345 Bytes

Contents

from functools import reduce


def hexa(hex_str):
    hex_str = hex_str.lower()
    if set(hex_str) - set('0123456789abcdef'):
        raise ValueError('Invalid hexadecimal string')
    digits = [ord(c) - ord('a') + 10 if c in 'abcdef' else ord(c) - ord('0')
              for c in hex_str]
    return reduce(lambda x, y: x * 16 + y, digits, 0)

Version data entries

125 entries across 125 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.179 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.178 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.177 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.176 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.175 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.174 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.173 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.172 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.171 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.170 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.169 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.167 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.166 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.165 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.164 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.163 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.162 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.161 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.160 tracks/python/exercises/hexadecimal/example.py