1

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??

2
  • Don't create a new dictionary, but rather update the original one. Commented Dec 26, 2021 at 19:35
  • how should i do that? Commented Dec 26, 2021 at 19:37

1 Answer 1

0

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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.