9

An alternate approach The routine is same for all types of inputs, except for when the len(list) == 1. This is why we can use a generator function to simplify the routine, and then a simple if statement to work with the exception def comma_code(iterable): result = ', '.join(str(value) for value in iterable[:-1]) return f"{result}, and {...


6

There are a couple of bad patterns in here, for what is an otherwise not bad looking code for a beginner. The most important of them is to not do the following (this is an example): def do_something(): something = another_variable_defined_below * 2 # bunch of code something=3 So, looking at : def right_riemann_sum(): total_area = 0 for k in ...


6

Well done First I like your attitude "for the future me". Keep that clean-coding practice. It will truely help. Handle edge cases aside I would extract the junction-part (", ", " and ") and particularly the single case ("Just "): def print_joined(iterable): # in unlikely case of nothing (fail-fast) if len(iterable) ...


4

After some tests, the code does look correct, but the logic takes some time to parse and understand, which is a significant disadvantage; when writing good, maintainable code, readability is usually the most important factor to consider. If a script is running too slowly for your liking, you can run a performance test to identify the bottleneck(s) and then ...


2

Due to the size of the program, I have only a few things to suggest Since you aren't returning anything from main(), use int main(void). Use don't have to perform any arithmetic in the inner nested-loop, you only need to do j <= i 3 in the outer-loop is a magic number or, an unnamed numeric constant. I suggest you assign it to const int rows, to make it ...


2

If I saw this code in an interview I would want to look at multiple factors, including: how well the code works how readable the code is Obviously the code works for the given input. In terms of readability it seems the code has consistent indentation, though some of the lines are quite long and I have to scroll horizontally to read the entire contents. ...


1

Complexity and performance review JavaScript does not like strings. It is always best to avoid direct string manipulation in JavaScript when compared to manipulating numbers. As the function involves stepping over each character you can get a lot of performance by converting characters to numbers using String.charCodeAt. Not all JavaScript numbers are ...


Only top voted, non community-wiki answers of a minimum length are eligible