Pitchkrak
Pitchkrak

Reputation: 370

Nested Tuple conversion to List

I have some very edgy behavior that I want to circumvent in python. Imagine that you have such structure:

something = {
 "data":{"mytuple":(1,2,3)}
}

Now I would like to access that tuple, for that I can do hthe following:

myGetter = something['data']['mytuple']

If I check that the data are the same, it is returning True

myGetter is something['data']['mytuple'] ## True

When I try to then convert that variable to a list, it works, but my nested data is not changed.
I suspect it is coming from memory allocation and the fact that the tuple is immutable.

myGetter = list(myGetter)

type(myGetter) ## return list
type(something['data']['mytuple']) ## still tuple

myGetter is something['data']['mytuple'] ## now returns False

Is there any way to modify the variable I created so it is replicated to the nested structure ?

Upvotes: 0

Views: 42

Answers (0)

Related Questions