Skip to content

Commit

Permalink
Merge pull request #385 from mggg/simplify-assignment-iterators
Browse files Browse the repository at this point in the history
Simplify Assignment iterators
  • Loading branch information
gabeschoenbach authored Feb 11, 2022
2 parents e818a5a + e21d974 commit 6f4e9b9
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions gerrychain/partition/assignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections import defaultdict
from itertools import chain, repeat
from collections.abc import Mapping

import pandas
Expand Down Expand Up @@ -70,17 +69,13 @@ def update_flows(self, flows):
def items(self):
"""Iterate over ``(node, part)`` tuples, where ``node`` is assigned to ``part``.
"""
for part, nodes in self.parts.items():
for node in nodes:
yield (node, part)
yield from self.mapping.items()

def keys(self):
return chain(*self.parts.values())
yield from self.mapping.keys()

def values(self):
return chain(
*(repeat(value, times=len(keys)) for value, keys in self.parts.items())
)
yield from self.mapping.values()

def update_parts(self, new_parts):
"""Update some parts of the assignment. Does not check that every node is
Expand Down

0 comments on commit 6f4e9b9

Please sign in to comment.