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.98 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.97 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.96 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.95 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.94 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.93 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.92 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.91 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.90 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.89 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.88 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.87 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.86 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.85 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.84 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.83 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.82 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.81 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.80 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.79 tracks/python/exercises/hexadecimal/example.py