Problem with list operation / function | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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 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.
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
18th Jul 2020, 2:25 PM
Mir Abir Hossain
Mir Abir Hossain - avatar