New course! Every coder should learn Generative AI!
Try a free lesson+ 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 Answers
+ 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 ๐๐ข๐ข๐๐จ ๐๐ก๐๐ฒ๐๐ฅ ^_^