From a66fcfaf2bd106649bc6d0b76e916ba80c962b80 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Sat, 17 May 2025 17:34:56 +0200 Subject: [PATCH] examples/topology: define socketIds and siblingsIds as sets socketIds and siblingsIds are declared as empty lists, filled by list comprehensions, and later on re-used as sets. They could be directly obtained from set comprehensions. Fixes: 34aa32b ("Move python example programs into python/examples/ subdirectory") Fixes: 3f4e32c ("examples: Invoke print("...") instead of print "..."") Link: https://docs.python.org/3/tutorial/datastructures.html#sets Signed-off-by: Ariel Otilibili Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- examples/topology.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/topology.py b/examples/topology.py index c39ee9c..2fcc25c 100755 --- a/examples/topology.py +++ b/examples/topology.py @@ -26,23 +26,18 @@ host = caps.getElementsByTagName('host')[0] cells = host.getElementsByTagName('cells')[0] total_cpus = cells.getElementsByTagName('cpu').length -socketIds = [] -siblingsIds = [] - -socketIds = [ +socketIds = { proc.getAttribute('socket_id') for proc in cells.getElementsByTagName('cpu') - if proc.getAttribute('socket_id') not in socketIds -] +} -siblingsIds = [ +siblingsIds = { proc.getAttribute('siblings') for proc in cells.getElementsByTagName('cpu') - if proc.getAttribute('siblings') not in siblingsIds -] +} print("Host topology") print("NUMA nodes:", cells.getAttribute('num')) -print(" Sockets:", len(set(socketIds))) -print(" Cores:", len(set(siblingsIds))) +print(" Sockets:", len(socketIds)) +print(" Cores:", len(siblingsIds)) print(" Threads:", total_cpus)