Methods to search and replace values in nested lists
<p>I'd like to search and replace values in a list of of list. I've cobbled together answers to:</p>

<ol>
<li><a href="http://stackoverflow.com/a/952952/2694260">Flatten a nested list</a></li>
<li><a href="http://stackoverflow.com/a/1540069/2694260">Search for and replace a value</a></li>
<li><a href="http://stackoverflow.com/a/6615011/2694260">Regroup the flat list into a list of lists</a></li>
</ol>

<p>My current code works however I feel that it's more convoluted then it needs to be. Is there a more elegant way of doing this?</p>

<pre><code># Create test data- a list of lists which each contain 2 items
numbers = list(range(10))
list_of_lists = [numbers[i:i+2] for i in range(0, len(numbers), 2)]

# Flatten the list of lists
flat_list = [item for sublist in list_of_lists for item in sublist]
# Search for and replace values
modified_list = [-1 if e &gt; 5 else e for e in flat_list]
# Regroup into a list of lists
regrouped_list_of_lists = [modified_list[i:i+2] for i in range(0, len(modified_list), 2)]
</code></pre>

<p>You're already using list comprehensions, just combine them:</p>

<pre><code>replaced_list_of_lists = [
            [-1 if e &gt; 5 else e for e in inner_list]
                for inner_list in list_of_lists
        ]
</code></pre>

python