Skip to content

Instantly share code, notes, and snippets.

@willmcgugan
Last active August 1, 2022 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmcgugan/61993ecf362a298bebfae10f49dea906 to your computer and use it in GitHub Desktop.
Save willmcgugan/61993ecf362a298bebfae10f49dea906 to your computer and use it in GitHub Desktop.
Dict views are amazing
from typing import NamedTuple
class Region(NamedTuple):
x: int
y: int
width: int
height: int
render_map = {
"header": Region(0, 0, 80, 24),
"footer": Region(0, 23, 80, 24),
"sidebar": Region(0, 0, 30, 24),
}
new_render_map = render_map.copy()
# Change position
new_render_map["sidebar"] = Region(-2, 0, 30, 24)
# New widget
new_render_map["modal"] = Region(10, 2, 60, 20)
# Get widgets which are new or changed
print(render_map.items() ^ new_render_map.items())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment