score:2

Accepted answer

You may use the following:

list = list.Select(x => x.Where(i => i % 2 == 1).ToList())
           .Where(x => x.Any())
           .ToList();

Here, we're using Select() to iterate the elements of the outer list, then using Where() to filter the inner list. After that, we call Where() on the outer list to filter out empty inner lists. That last part is optional; feel free to remove it if you need to keep empty lists.

Note: As @Dmitry stated in the comments, it's probably better to use i % 2 != 0 if you want to keep negative odd numbers.


Related Articles