To start off I'd like to note I am aware of int(val, base)
. My goal was to write a short function capable of taking in a base int
, and a string defining the value to be summed.
The function rests upon the equation:
represented_value = value * base ^ placeholder
>>> base_v = lambda base_v, num_a: sum(int(num_a[len(num_a) - ph - 1]) * base_v ** ph for ph in range(len(num_a)))
>>> base_v(10, "123")
123
>>> base_v(100, "123")
10203
I can even do something silly like:
>>> base_v(-10, "123")
83
>>>
>>> base_v(-10, ["123", "123", "123"])
11193
I am curious how this function can be made more succinct and what pitfalls it may have.
null
or"hello"
? \$\endgroup\$