Refactoring: combine two pairs of loops into single loops
In both cases, the first loop only created a list over which the second
loop iterated. We can simply skip creating the intermediate list.
@@ -92,19 +92,17 @@ def get_cpu_cores_per_run(
logging.debug("List of available CPU cores is %s.", allCpus)
# read mapping of core to memory region
- memory_regions = []
+ cores_of_memory_region = collections.defaultdict(list)
for core in allCpus:
coreDir = "/sys/devices/system/cpu/cpu{0}/".format(core)
- memory_regions.append(_get_memory_banks_listed_in_dir(coreDir)[0])
- cores_of_memory_region = collections.defaultdict(list)
- for core, memory_region in zip(allCpus, memory_regions):
+ memory_region = _get_memory_banks_listed_in_dir(coreDir)[0]
cores_of_memory_region[memory_region].append(core)
logging.debug("Memory regions of cores are %s.", cores_of_memory_region)
# read mapping of core to CPU ("physical package")
- physical_packages = [get_cpu_package_for_core(core) for core in allCpus]
cores_of_package = collections.defaultdict(list)
- for core, package in zip(allCpus, physical_packages):
+ for core in allCpus:
+ package = get_cpu_package_for_core(core)
cores_of_package[package].append(core)
logging.debug("Physical packages of cores are %s.", cores_of_package)
