Python: How to create a common element between a list and a dict

前端 未结 4 2162
旧时难觅i
旧时难觅i 2021-01-22 14:57

I am new to data structures in python and was wondering how do you simulate a thing like pointers in python so that multiple structures can refer and manage the same piece of da

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-22 15:23

    i have tried the following peice of code and it works (changing in one DataStructure changes for the other). does this help?

    list1 = [1,2,3]
    list2 = [4,5,6]
    
    my_dictionary = {}
    my_dictionary["a"] = list1
    my_dictionary["b"] = list2
    
    del list1[0]
    print list1
    print list2
    print my_dictionary
    

提交回复
热议问题