Last active
August 1, 2022 18:43
-
-
Save willmcgugan/61993ecf362a298bebfae10f49dea906 to your computer and use it in GitHub Desktop.
Dict views are amazing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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