+ 1

y its not printing

>>> list_1 = ['sugar', 'pepper', 'vegitables', 'fruits', 'groccery'] >>> list_2 = ['furniture', 'books', 'computers'] >>>Final_list = [list_1 + list_2] >>> list_1.append('butter') >>> list_1.append('icecream') >>> list_1.append('wweshow') >>> print(Final_list) [['sugar', 'pepper', 'vegitables', 'fruits', 'groccery', 'furniture', 'books', 'computers']] y its not printing "wweshow"? but when i do this >>> print (list_1) ['sugar', 'pepper', 'vegitables', 'fruits', 'groccery', 'butter', 'icecream', 'wweshow'] it prints out"wweshow" second thing del list_1[1] >>> print (Final_list) ['sugar', 'pepper', 'vegitables', 'fruits', 'groccery', 'butter', 'icecream', 'wweshow', 'furniture', 'books', 'computers'] its(pepper) not deleted, y? but when i do this >>> print (list_1) ['sugar', 'vegitables', 'fruits', 'groccery', 'butter', 'icecream', 'wweshow'] u see, "pepper" is gone what's happening here

25th Oct 2017, 5:22 AM
AppInventor
AppInventor - avatar
4 Answers
+ 4
Imagine your lists as two sheets of paper with some items written on them... Now, say that your new Final_list is build by concatenate those two (paper) lists: instead of doing concatenation of original (paper) lists, concatenation will first make copy of each of your original list on a new paper sheets, rather than stick your original paper sheets together. So, if you modify your original paper lists after making the concatenation, you doesn't modify the new created one, and reciprocally ;P
25th Oct 2017, 6:45 AM
visph
visph - avatar
+ 3
Because when you concatenate two lists, you create a new one by copying the two original, not just linking them... So your Final_list will only reflect the state of list_1 and list_2 at time of concatenation, not later, if any of them is updated ^^
25th Oct 2017, 6:09 AM
visph
visph - avatar
0
i see u mean it will not print out updates(to any list) but how about Final_list = (list1 +list2) i thought when i print FINAL LIST it will put updates and other previous items in an output but u say it won't is there way in python to get what i want here or not? thanks @visph
25th Oct 2017, 6:42 AM
AppInventor
AppInventor - avatar
0
got it
25th Oct 2017, 7:12 AM
AppInventor
AppInventor - avatar