Is it important to use numpy
or not? But I tried to use it and didn't succeed.
This is the code:
c = []
a = list(range(10))
c.append(a)
b = list(range(5))
c.append(b)
How to add 1
to all the elements of c
?
Is it important to use numpy
or not? But I tried to use it and didn't succeed.
This is the code:
c = []
a = list(range(10))
c.append(a)
b = list(range(5))
c.append(b)
How to add 1
to all the elements of c
?
you can do this.
c = [[sum(x) for x in zip(y, [1]*len(y))] for y in c]
We can use two list comprehensions to do what you desire. The outer loop iterates over the lists in c
, and the inner loop iterates over the values in each list of c
:
c = []
a = list(range(10))
c.append(a)
b = list(range(5))
c.append(b)
[[val+1 for val in list] for list in c]