Problem with list operation / function | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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

18th Jul 2020, 8:31 AM
Mir Abir Hossain
Mir Abir Hossain - avatar
5 Respostas
+ 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.
18th Jul 2020, 9:45 AM
ThƩophile
ThƩophile - avatar
+ 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.
18th Jul 2020, 8:36 AM
AKSHAYšŸ‡®šŸ‡³
AKSHAYšŸ‡®šŸ‡³ - avatar
+ 2
šŠš¢š¢š›šØ š†š”ššš²ššš„ the resource is really great. special thanks to mention this. :)
18th Jul 2020, 2:54 PM
Mir Abir Hossain
Mir Abir Hossain - avatar
+ 1
Thanks AKSHAY , for the answer
18th Jul 2020, 9:05 AM
Mir Abir Hossain
Mir Abir Hossain - avatar