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 18, 2024
1 parent 05790e1 commit 5bf9471
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 @@ -76,7 +76,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 @@ -85,7 +85,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 5bf9471

Please sign in to comment.