From b100fb3ecf2e24a191d4d82abbef28a59222d727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Mon, 23 Oct 2023 18:37:36 +0200 Subject: [PATCH] Use defaultdict to shorten code --- src/ert/gui/model/snapshot.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ert/gui/model/snapshot.py b/src/ert/gui/model/snapshot.py index 1ad5c7c4040..09476da9536 100644 --- a/src/ert/gui/model/snapshot.py +++ b/src/ert/gui/model/snapshot.py @@ -117,17 +117,11 @@ def prerender( if isinstance(snapshot, Snapshot): metadata[SORTED_REALIZATION_IDS] = sorted(snapshot.reals.keys(), key=int) - metadata[SORTED_JOB_IDS] = defaultdict(dict) - for idx, _ in job_states.items(): - real_id, job_id = idx - if real_id not in metadata[SORTED_JOB_IDS]: - metadata[SORTED_JOB_IDS][real_id] = [] + metadata[SORTED_JOB_IDS] = defaultdict(list) + for (real_id, job_id), _ in job_states.items(): metadata[SORTED_JOB_IDS][real_id].append(job_id) - for idx, job_status in job_states.items(): - real_id, job_id = idx - - # partial snapshot may contain only information about job state + for (real_id, job_id), job_status in job_states.items(): if real_id in reals and reals[real_id].status: metadata[REAL_STATUS_COLOR][real_id] = _QCOLORS[ state.REAL_STATE_TO_COLOR[reals[real_id].status]