python - Copy reference and concatenate lists -
python - Copy reference and concatenate lists -
when have several objects , set them list, list holds references objects. need same behaviour lists themselves.
so lets have:
list1 = [1,2,3] list2 = [4,5,6] ...
i want have alllists this:
alllists = [list1, list2, ..., listn]
but python this:
list1 = [1,2,3] list2 = [4,5,6] ... alllists = [1, 2, 3, 4, 5, 6, ...]
i tried append, insert, concatenate or utilize + operator, python copies content info of each list alllists instead of copying referencs of list1 listn , save references in alllists.
is possible, references of list1 listn in alllists?
you can't things way want to. you're going need create new list , append lists individually
in [1]: super_list = [] in [2]: list1 = [1,2,3] in [3]: list2 = [4,5,6] in [4]: super_list.append(list1) in [5]: super_list.append(list2) in [6]: super_list out[6]: [[1, 2, 3], [4, 5, 6]]
python list reference concatenation
Comments
Post a Comment