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.78 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.77 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.76 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.75 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.74 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.73 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.72 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.71 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.70 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.69 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.68 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.67 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.66 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.65 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.64 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.63 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.62 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.61 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.60 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.59 tracks/python/exercises/hexadecimal/example.py