Why does pycharm propose to change method to static

PyCharm “thinks” that you might have wanted to have a static method, but you forgot to declare it to be static (using the @staticmethod decorator). PyCharm proposes this because the method does not use self in its body and hence does not actually change the class instance. Hence the method could be static, i.e. callable without passing a class instance or without even … Read more

Viewing all defined variables

A few things you could use: dir() will give you the list of in scope variables: globals() will give you a dictionary of global variables locals() will give you a dictionary of local variables

Python map object is not subscriptable

In Python 3, map returns an iterable object of type map, and not a subscriptible list, which would allow you to write map[i]. To force a list result, write However, in many cases, you can write out your code way nicer by not using indices. For example, with list comprehensions:

Breaking out of nested loops

It has at least been suggested, but also rejected. I don’t think there is another way, short of repeating the test or re-organizing the code. It is sometimes a bit annoying. In the rejection message, Mr van Rossum mentions using return, which is really sensible and something I need to remember personally. 🙂

NumPy List Comprehension Syntax

First, you should not be using NumPy arrays as lists of lists. Second, let’s forget about NumPy; your listcomp doesn’t make any sense in the first place, even for lists of lists. In the inner comprehension, for i in X is going to iterate over the rows in X. Those rows aren’t numbers, they’re lists (or, in … Read more

Create an empty list in Python with certain size

You cannot assign to a list like lst[i] = something, unless the list already is initialized with at least i+1 elements. You need to use append to add elements to the end of the list. lst.append(something). (You could use the assignment notation if you were using a dictionary). Creating an empty list: Assigning a value … Read more