+ 2
Problem with list operation / function
Can anybody tell me why after 'wow' function is executed on 'a' list, the original list is not changed,but after 'nice' function executed on 'b' list, the original list is changed? https://code.sololearn.com/c7eUYVGiq4Zk/?ref=app
5 Antworten
+ 3
1st case : a new list is created from an iterator (filter) on the list given into parameter. This iterator doesn't modify the original list.
2nde case : the '+=' operator. On lists, this operator behaves in the same way as the '.append' method : it modifies directly the list. Since it's confusing, please use 'append' method over '+=' operator.
+ 2
Mir Abir Hossain its because filter function generates new list based on the function you apply and original list doesn't change.
And in 2nd case you added 2 to every value in list or you have changed the values in the list.
So, the 2nd list change and 1st didn't.
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 the resource is really great. special thanks to mention this. :)
+ 1
Thanks AKSHAY , for the answer
+ 1
Thank you Théophile and 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ^_^