There are two lists.

The first:

key = ['load.scenarios.attempts', 'load.scenarios.succeeds', 'load.scenarios.fails', 'load.scenarios.aborts', 'load.scenarios.attempts_ps', 'load.scenarios.succeeds_ps', 'load.scenarios.fails_ps', 'load.scenarios.aborts_ps'] 

Second:

 val = ['Total', 'Per Second'] 

You need to create a dictionary of the following type:

 {'load.scenarios.attempts' : 'Total', ..., 'load.scenarios.attempts_ps' : 'Per Second'} counters = {} for k, v in zip(key, val): counters[k] = v print(counters) 

But the cycle ends when the values ​​of v end. But the main problem is to arrange it in the specified order.

What would "Total" refer only to 'load.scenarios.attempts' to such values.

And "Per Second" only where there is 'load.scenarios.attempts_ps' (_ps)

    2 answers 2

     items = [ 'load.scenarios.attempts', 'load.scenarios.succeeds', 'load.scenarios.fails', 'load.scenarios.aborts', 'load.scenarios.attempts_ps', 'load.scenarios.succeeds_ps', 'load.scenarios.fails_ps', 'load.scenarios.aborts_ps' ] item_by_value = {x: 'Per Second' if x.endswith('_ps') else 'Total' for x in items} print(item_by_value) 

    Result:

    {'load.scenarios.attempts_ps': 'Per Second', 'load.scenarios.fails_ps': 'Per Second', 'load.scenarios.attempts': 'Total', 'load.scenarios.fails': 'Total', 'load.scenarios.succeeds': 'Total', 'load.scenarios.aborts_ps': 'Per Second', 'load.scenarios.aborts': 'Total', 'load.scenarios.succeeds_ps': 'Per Second'}

    • Thanks, got it! - Andrey Sindeev
    • @AndreySindeev, then mark the answer as correct, so that the question without an answer does not hang - gil9red
     key = ['load.scenarios.attempts', 'load.scenarios.succeeds', 'load.scenarios.fails', 'load.scenarios.aborts', 'load.scenarios.attempts_ps', 'load.scenarios.succeeds_ps', 'load.scenarios.fails_ps', 'load.scenarios.aborts_ps'] res = {k: {'_ps': 'Per Second'}.get(k[-3:], 'Total') for k in key} # {'load.scenarios.attempts': 'Total', 'load.scenarios.succeeds': 'Total', 'load.scenarios.fails': 'Total', 'load.scenarios.aborts': 'Total', 'load.scenarios.attempts_ps': 'Per Second', 'load.scenarios.succeeds_ps': 'Per Second', 'load.scenarios.fails_ps': 'Per Second', 'load.scenarios.aborts_ps': 'Per Second'}