+ 2
Help me to solve the code #0012
explain in deatil.. why it leaves values behind..? https://code.sololearn.com/cHRFSX8Mn1s9/?ref=app
2 Answers
+ 1
I added some prints statements to the code so you can see better what is going on. I added comments too.
https://code.sololearn.com/cwiJxQYWJ0YZ/?ref=app
+ 1
Dear Pradipsinh, please take a look at the following code with my commentaries and explanation for each loop cycle step in and step out: https://code.sololearn.com/c10Zvkd9xlK1/#py
Alternatively, run this code:
numlist = [1, 2, 3, 4 ,5]
position = 1
for num in numlist:
print('\nBEFORE THE NEXT .REMOVE(n): {}'.format(numlist))
print('POSITION: {}'.format(position))
print('NUM TO REMOVE: {}'.format(num))
numlist.remove(num)
print('AFTER THE .REMOVE(n): {}'.format(numlist))
position += 1
Hope it helps! Have a great weekend, friend