+ 3

Would you please help me to understand this code Logic ?

Would you please help me to understand two things ? The code goal and logic (each line) https://code.sololearn.com/cl59hl44i8Z8/#py

28th Apr 2018, 9:10 PM
NIMA
NIMA - avatar
5 odpowiedzi
+ 4
The one_to_2D function receives three arguments: 1. A list 2. A range 3. A number of elements Within the function a new empty list is declared. Subsequently iterates with the established range. The rank is the number of elements that your new list will have: if r = 2 then your list will have two elements (that is, the list will have two lists inside it: [[], []]). Within the cycle you add to the list that you declared within the function a certain number of elements (the quantity is defined by the argument c). The notation that you see there ( [:c] ) only means that you will take that number of elements (the value of c) from the beginning of the list (that means that in the first iteration you will take the values ​​[8, 2, 9] in this case). Then return a new list with the items you took and delete them (since they are not necessary). At the end of the function you only return your new list. Subsequently there is a statement of three variables, each corresponds to the arguments I mentioned earlier. And in the end you simply print the result of the function. PS: I'm not very good at Python, so maybe I'm interpreting something wrong.
28th Apr 2018, 9:49 PM
Mickel
Mickel - avatar
+ 3
I LOVE print statements. They are a great way to debug and well, understand how a code works. Check out the code below. I put print statements before almost all statements so you can see very clearly what is going on when you run it. Sorry if you feel I went overboard. https://code.sololearn.com/cwBaCa3CZ4QY/?ref=app
29th Apr 2018, 12:33 AM
cyk
cyk - avatar
0
ok Im gonna try
28th Apr 2018, 9:22 PM
andrebtw
andrebtw - avatar
0
I dont understand it too
28th Apr 2018, 9:24 PM
andrebtw
andrebtw - avatar
0
sorry
28th Apr 2018, 9:24 PM
andrebtw
andrebtw - avatar