How to subtract a constant from members of a sublist?
<p>I know I can subtract a constant from all members of a simple list like this:</p>

<pre><code>l = [ 123, 124, 125, 126 ]
l = [v - 100 for v in l]
</code></pre>

<p>But how can I subtract a constant from one or more specific members of each sublist within a list?</p>

<p>Suppose I have:</p>

<pre><code>l = [ [101, 102, 103], [111, 122, 133], [222, 333, 444] ]
</code></pre>

<p>I want to subtract, say, 100 from the 2nd and 3rd elements of each sublist, to give me:</p>

<pre><code>[ [101, 2, 3], [111, 22, 33], [222, 233, 344] ]
</code></pre>

<p>Is there a straightforward Pythonic way to do this?</p>

<p>In a simplest form, you can unpack the sublists and apply the operation to the desired items:</p>

<pre><code>In [1]: l = [ [101, 2, 3], [111, 22, 33], [222, 233, 344] ]

In [2]: [[x, y - 100, z - 100] for x, y, z in l]
Out[2]: [[101, -98, -97], [111, -78, -67], [222, 133, 244]]
</code></pre>

<p>Or, a bit more scalable approach would be to have a nested list comprehension:</p>

<pre><code>In [3]: [[item[0]] + [x - 100 for x in item[1:]] for item in l]
Out[3]: [[101, -98, -97], [111, -78, -67], [222, 133, 244]]
</code></pre>

python list-comprehension