Skip to content

Commit

Permalink
utils.updatedDict() added
Browse files Browse the repository at this point in the history
  • Loading branch information
ibressler committed Jun 7, 2021
1 parent 4367a6c commit 03fe42c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# utils.py

import os, sys
import copy
import urllib
import json
import ipykernel
Expand Down Expand Up @@ -133,3 +134,9 @@ def fmtErr(val, std, precision = 2, width = None):
fmt = "{:"+str(width)+"."+str(precision)+"f}({:.0f})"
#print("fmtErr val:", val, "std:", std)
return fmt.format(val, std * 10**(precision))

def updatedDict(d, key, value):
"""Implements the |= operator for dict in Python version <3.9."""
dd = copy.copy(d)
dd[key] = value
return dd

0 comments on commit 03fe42c

Please sign in to comment.