List Comprehension in Python. | Sololearn: Learn to code for FREE!


List Comprehension in Python.

I have a Nested list in python which is structured like this.. [ [1,2,3] [4,5,6] [7,8,9] ] I want to use List Comprehension specifically, to iterate over all the items in the list and add 0.1 to them and produce a new list. Any idea on how can i do that.

4/27/2019 4:26:31 AM


2 Answers

New Answer


l = [ [1,2,3], [4,5,6], [7,8,9], ] n = [[j+0.1 for j in i] for i in l] It might be easier to use a numpy array though:


Oh okay. So the trick was to loop over row in the outer for loop and column in the inside. I used to get error saying inner iterator variable isn't declared. Great help ! Thank you. Solved my problem.