What is an alternative for using a list in a dictionary to be able to reference the same list in different scopes?
Question:
I want an alternative to this approach:
a = {'_': [1, 2, 3]}
def func(a: dict):
a['_'][1] = 3
def func2(a: dict):
a['_'][0] = 3
func(a)
func2(a)
>>> a
{'_': [3, 3, 3]}
Answers:
What is an alternative for using a list in a dictionary to be able to reference the same list in different scopes?
Using a list…
a = [1, 2, 3]
def func(a: list):
a[1] = 3
def func2(a: list):
a[0] = 3
func(a)
func2(a)
>>> a
[3, 3, 3]
I want an alternative to this approach:
a = {'_': [1, 2, 3]}
def func(a: dict):
a['_'][1] = 3
def func2(a: dict):
a['_'][0] = 3
func(a)
func2(a)
>>> a
{'_': [3, 3, 3]}
What is an alternative for using a list in a dictionary to be able to reference the same list in different scopes?
Using a list…
a = [1, 2, 3]
def func(a: list):
a[1] = 3
def func2(a: list):
a[0] = 3
func(a)
func2(a)
>>> a
[3, 3, 3]