Skip to content

Commit

Permalink
update dict-key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Corvince committed Sep 15, 2024
1 parent 03a9b11 commit 384a7ce
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesa/experimental/cell_space/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def connect(self, other: Cell, name: str | None = None) -> None:
"""
if name is None:
name = str(other.coordinate)
self.connections.update({name: other})
self.connections[name] = other

def disconnect(self, other: Cell) -> None:
"""Disconnects this cell from another cell.
Expand All @@ -83,7 +83,9 @@ def disconnect(self, other: Cell) -> None:
other (Cell): other cell to remove from connections
"""
self.connections = {k: v for k, v in self.connections.items() if v != other}
keys_to_remove = [k for k, v in self.connections.items() if v == other]
for key in keys_to_remove:
del self.connections[key]

def add_agent(self, agent: CellAgent) -> None:
"""Adds an agent to the cell.
Expand Down

0 comments on commit 384a7ce

Please sign in to comment.