use dict.get() in column_header_replacement function
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 Apr 2023 12:55:53 +0000 (13:55 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 Apr 2023 12:55:53 +0000 (13:55 +0100)
openpower/sv/rfc/ls012_optable.py

index 4aeb831e0afed8b7b32200adcfb830b4649f6292..592b83b90849f6747d3f5590a199e8cf087df2f6 100644 (file)
@@ -77,19 +77,19 @@ def by_cost_then_priority_then_page(areas):
         costs[cost].append(row)
     return costs
 
+
 # For prettier printing, replace short column heading
 # names with full, consistent names.
 # Expected input is a list of column strings
 def column_header_replacement(header):
     replacement_col = {'cost': 'XO Cost'}
-    new_header = header
-    for shortname in replacement_col.keys():
-        # check if header contains any shortnames
-        if shortname in header:
-            index = header.index(shortname)
-            new_header[index] = replacement_col[shortname]
+    new_header = deepcopy(header)
+    for index, shortname in enumerate(replacement_col.keys()):
+        # update with replacement if any otherwise leave alone
+        new_header[index] = replacement_col.get(shortname, shortname)
     return new_header
 
+
 def print_table(title, header, areas, sortby):
     fname = title.lower().replace(" ", "_")
     with open("ls012/%s.mdwn" % fname, "w") as f: