Feb-02-2019, 06:19 PM
My university book has lots of exercises to practice and i found this one which wants to make a list with lists and then find sum of each list.
As example it gives that the result should be something like this:
ex1=[[1],[1,2],[1,2,3],[1.2.3.4]]
so when i am trying to make this list with this code
[[1, 2, 3, 4], [1, 2, 3], [1, 2], [1], []]
which is reversed of what the book wants and also i get an empty [].
why is that happening?
i found why there is the empty [] and i change the code into this:

[[1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]
[quote='sonedap' pid='70631' dateline='1549127665']
As example it gives that the result should be something like this:
ex1=[[1],[1,2],[1,2,3],[1.2.3.4]]
so when i am trying to make this list with this code
ex1=[] for i in range (5): ex1.append(range(1,5-i)) print(ex1)i get this result:
[[1, 2, 3, 4], [1, 2, 3], [1, 2], [1], []]
which is reversed of what the book wants and also i get an empty [].
why is that happening?
i found why there is the empty [] and i change the code into this:
ex1=[] for i in range (4): ex1.append(range(1,5-i)) print(ex1)but i still get the reverse result.

[[1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]
[quote='sonedap' pid='70631' dateline='1549127665']