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.139 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.138 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.137 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.136 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.135 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.134 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.133 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.132 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.131 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.130 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.129 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.128 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.127 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.126 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.125 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.124 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.123 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.122 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.121 tracks/python/exercises/hexadecimal/example.py
trackler-2.2.1.120 tracks/python/exercises/hexadecimal/example.py