List comprehension list of lists

list, python, python-2.7

Solution

Use this:

[[number+1 for number in group] for group in x]

Or use this if you know map:

[map(lambda x:x+1 ,group) for group in x]

Problem

I have a list of lists, and would like to use list comprehension to apply a function to each element in the list of lists, but when I do this, I end up with one long list rather than my list of lists. So, I have ``` x = [[1,2,3],[4,5,6],[7,8,9]] [number+1 for group in x for number in group] [2, 3, 4, 5, 6, 7, 8, 9, 10] ``` But I want to get ``` [[2, 3, 4], [5, 6, 7], [8, 9, 10]] ``` How do I go about doing this?

Original source