Skip to content
Advertisement

Iterate through dict with keys being strings with index

I have a dictionary in the following form:

JavaScript

I need to get 4 lists of the following form:

JavaScript

I am trying to find a way to do it by including the key, for example to have an index form 1 to 2 and do string matching with "Pbat_ch["+str(index)+"]". Any better idea of how to achieve that?

Advertisement

Answer

As your “indices” are always in order and consecutive, use a simple collection in a defaultdict after reworking the key:

JavaScript

output:

JavaScript

accessing a given sublist:

JavaScript

Or as list of lists:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement