New answers tagged

3

Re-implementing a dict is completely unnecessary. codecs.register() expects a search function, so a plain function will work just fine. You can use a regular dict to store codecs (in a closure). Normalization can be implemented in its own function. Something as simple as this should work: def register_codecs(*encodings: Iterable[str]) -> None: ...


2

Your code is pretty much perfect, the only problem is that you chose to sacrifice some performance in most cases (non 0 operands) for the sake of making the rare case faster. Here's a slight improvement based on the assumption that most of the times none of the operands will be 0. The trick is to keep it efficient in the case of 0 without wasting time on ...


1

It seems like your code is intended to count how many times 1 needs to be doubled (1 << a) to reach the provided value, n. The code works, but the style is convoluted. Noctis Skytower provided a more straight-forward solution. Since the program expects positive integers, the end condition occurs when number is 0. For every iteration in which number is ...


Top 50 recent answers are included