How can I use list comprehensions to process a nested list?

Here is how you would do this with a nested list comprehension:

[[float(y) for y in x] for x in l]

This would give you a list of lists, similar to what you started with except with floats instead of strings.

If you want one flat list, then you would use

[float(y) for x in l for y in x]

Note the loop order – for x in l comes first in this one.

Leave a Comment