+ 2

Help me to solve the code #0012

explain in deatil.. why it leaves values behind..? https://code.sololearn.com/cHRFSX8Mn1s9/?ref=app

23rd Mar 2018, 4:14 PM
Pradipsinh Jadeja
Pradipsinh Jadeja - avatar
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
23rd Mar 2018, 4:19 PM
cyk
cyk - avatar
+ 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
23rd Mar 2018, 5:37 PM
Andrey Vostokov
Andrey Vostokov - avatar