When to drop list Comprehension and the Pythonic way?
问题 I created a line that appends an object to a list in the following manner >>> foo = list() >>> def sum(a, b): ... c = a+b; return c ... >>> bar_list = [9,8,7,6,5,4,3,2,1,0] >>> [foo.append(sum(i,x)) for i, x in enumerate(bar_list)] [None, None, None, None, None, None, None, None, None, None] >>> foo [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] >>> The line [foo.append(sum(i,x)) for i, x in enumerate(bar_list)] would give a pylint W1060 Expression is assigned to nothing, but since I am already using the foo