Skip to main content

New answers tagged

3 votes

A simple C++ function converting the environment variables in main() to an unordered_map

Structured binding One point not raised by previous reviews: the code would be cleaner using a structured binding in your loop over the map contents. As well as making the key and value ...
Chris's user avatar
  • 6,126
7 votes

Substitute patterns with values from lists

I would prefer to take Iterable[tuple[str, Iterable[str]]] rather than dict[str, list[str]] for two reasons: ...
Peilonrayz's user avatar
  • 44.6k
3 votes

Substitute patterns with values from lists

I'm not comfortable with that mutating pop, even if it is on a copy. Also, why not make the substitution state reusable? In the following style, subsequent calls on the same object will resume ...
Reinderien's user avatar
  • 71.2k
4 votes

Substitute patterns with values from lists

Given that the problem states enough replacement values must be provided to the function, it would seem reasonable to catch that IndexError and raise a ...
Chris's user avatar
  • 6,126
6 votes

Substitute patterns with values from lists

Tests It's nice to see that you have included various tests to verify that replace_in_string works as expected. Docstring Its great that you have provided a ...
Booboo's user avatar
  • 4,101
3 votes

Huffman code builder in Java - computing prefix codes for arbitrary (generic) alphabets - Take II

The HuffmanEncoder is not an encoder. It's a builder that constructs the code table for the symbols based on the weights. An encoder would take input and encode it ...
TorbenPutkonen's user avatar
3 votes

HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets

Minor but, Huffman only has a single n in the name. But let's move on to how the code words are built, the meat of the algorithm after all. ...
user555045's user avatar
  • 12.6k
3 votes

HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets

Style When I look at your formatting in the following snippet, for some reason you have a newline after the first argument to Double.compare, but this line would be ...
Chris's user avatar
  • 6,126
3 votes

A simple method for compressing white space in text (Java) - Take II

Just some remarks. By providing a capacity: new StringBuilder(textLength) - here a bit extra room, you prevent internal array resizing inside StringBuilder. For ...
Joop Eggen's user avatar
  • 4,716

Top 50 recent answers are included