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]} 
Asked By: davelopment

||

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]
Answered By: Tomerikoo
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.