May-12-2018, 04:19 PM
Dear Python-forum members,
I have registered to this forum because i have a small but resistant problem.
It is surely trivial, but i have not practiced Python for a long time and i don't remember the trick, and i would be grateful to benefit from someone's help.
(This def is to produce neighbors in a Hasse diagram).
Let "Collection" be a collection of vectors, initially empty.
From an initial vector that i call : "SET", i will produce other vectors that i will add to "Collection". Then i return "Collection".
To do this, I will add or remove elements of SET, and i add these vectors to "Collection".
My problem is that i don't want "SET" to change. When i write C=SET, i want to modify C, but i don't want "SET" to be modified when i modify C. However with this code, "SET" is modified when i modify C. (I can see the change with : print("SET before",SET); and : print("SET after",SET))
Thank you very much in advance,
Hassediagram
I have registered to this forum because i have a small but resistant problem.
It is surely trivial, but i have not practiced Python for a long time and i don't remember the trick, and i would be grateful to benefit from someone's help.
(This def is to produce neighbors in a Hasse diagram).
Let "Collection" be a collection of vectors, initially empty.
From an initial vector that i call : "SET", i will produce other vectors that i will add to "Collection". Then i return "Collection".
To do this, I will add or remove elements of SET, and i add these vectors to "Collection".
My problem is that i don't want "SET" to change. When i write C=SET, i want to modify C, but i don't want "SET" to be modified when i modify C. However with this code, "SET" is modified when i modify C. (I can see the change with : print("SET before",SET); and : print("SET after",SET))
def PHa(SET):
Collection=[]
for k in range(1,n+1):
if k not in SET:
C=SET
print("SET before",SET)
C.append(k)
print("SET after",SET)
Collection.append(C)
for k in range(1,n+1):
if k in SET:
C=SET
C.remove(k)
Collection.append(C)
return CollectionDoes someone know the trick to fix "SET" ?Thank you very much in advance,
Hassediagram
