append()
is a list method that modifies the list in-place. So a.append("foo")
changes a
by adding the element "foo"
at the end. These methods do not need to return anything, so they don't.
Therefore, if you build a list using a list comprehension that is constructed using the returned values of a series of append()
method calls, you'll get a series of None
s.
If you don't want to modify the original list, you can do something like
>>> print([item + [item[0]*4] for item in arr])
[[3, 2, 1, 12], ['a', 'b', 'c', 'aaaa'], [('do',), ['re'], 'mi', ('do', 'do', 'do', 'do')]]
If you do want to modify the original list, you should do
>>> for item in arr:
... item.append(item[0]*4)
...
>>> print(arr)
[[3, 2, 1, 12], ['a', 'b', 'c', 'aaaa'], [('do',), ['re'], 'mi', ('do', 'do', 'do', 'do')]]
But you shouldn't try doing both at the same time. Using side effects in list comprehensions is almost always a bad idea.