The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

12

This looks like a handy tool to have around, maybe we can make it even better. Style As per the official Python Style Guide (often known by his nickname PEP8), keyword-arguments of functions should have no whitespace around the =. Matrix size numpy arrays have a property called .shape which describes their number of rows and number of cols (in case of a ...


9

Python's string formatting has come a long way from the "%s" formatting days. Nowadays classes can even determine on their own how to handle format specifiers. Therefore I would write a matrix class that can be pretty printed with different format options determining the matrix style. class MathJaxMatrix: brackets = {'': 'matrix', 'p': '...


5

I normally don't like to do complete rewrites for reviews as I don't think that they're usually helpful. Here though, the major problem that I see with your code is you're trying to do far too much "manually". You aren't making good use of built-in Python constructs that automate some of the painful elements. You also have everything in one massive block. I ...


5

DRY Code There is a programming principle called the Don't Repeat Yourself Principle sometimes referred to as DRY code. If you find yourself repeating the same code multiple times it is better to encapsulate it in a function. If it is possible to loop through the code that can reduce repetition as well. This code repeats many times with minor variations: ...


3

One should almost never use a bare except clause. It should always list the exceptions to be caught. The code would be easier to read and understand, if it were written in section that each tested one aspect of a magic square. Like, is is a square, does it have all the numbers in sequence, do the rows add up to the magic number, do the columns, do the ...


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