Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

function is not modifying the argument?

Alright, this function’s supposed purpose is to simply modify the object "matrix" accordingly with the dictionary comprehension. However, I don’t want it to return anything. I just need the modifications to stick. Is that possible??

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I could resolve it by doing this:

def matrix_null(matrix: dict, null: float):
    to_pop = []
    for key, value in matrix.items():
    if value == null:
        to_pop.append(key)
    
    for key in to_pop:
        matrix.pop(key)
    
    matrix['null'] = null

# TEST:

matrix = {'abc': 123, '1': 1.0, '2': 1.0}

matrix_null(matrix, 1.0)

print(matrix)

>>> {'abc': 123, 'null': 1.0}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading