New answers tagged

1

Why are these two so different in speed? Casting as String was much faster: The cast is just a type check (1 or 2 JVM instructions), as iter.next()'s type should be String. The toString() call just does return this;, so it should be fast too. Actually, you can just write: String current = iter.next(); Correction: you could if you change the line to: ...


1

First of all, this is a very nicely written code. Before writing about the cur implementation, a few notes: I do not think n and m should be in main. It creates shadowing in the function. I added type annotation to the return value of the function. Since it's a generator it should be: Iterator[List[int]]. So you said you do not like the way cur is ...


5

Code block 1 Please don't use variable names like object, i or y. Standard indentation in Python is 4 spaces, not a mix between 2 and 4. Mutating values out of a functions scope isn't best practice. This is because it leads to confusing code. The following snippet is not needed. You can just use names[i]. y = "{0}".format(i + 1) names[int(y)-1] Rather ...


2

It seems this could be simplified with a small lookup table and then concatenating strings. Using a table as simple as: const lookup = { blue: 'b', green: 'f', purple: 'g', yellow: 'p' }; we can then lookup the color values and concatenate them together. Combined with a simple check to make sure the color is valid and the 2 colors aren't the same, ...


Top 50 recent answers are included