I want to create a n*n list in python with most of the elements initialized with None. Then I will set some elements in a for loop, but in the line I set diagonal elements to be 0, I got a warning highlight on [j] in PyCharm, saying:
"Unexpected type(s): (int, int) Possible types: (int, None) (slice, Iterable[None]) Inspection info: This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations."
I don't know where is wrong. If I change the 2d list to be all initialized as 0 in the first line, then this warning is gone. What makes None special here?
prev = [[None] * n for i in range(n)]
for i in range(n):
for j in range(n):
if i == j:
prev[i][j] = 0
......
python 3.6.1- SheldorePython 3.5.5andPython 2.7.15at Ubuntu 16.04 - BugKiller