0

My data will likely be in this format:

1-universal

Type_A=10, Type_B=20, Type_C=30

Local set 1:

Type_D=40, Type_C =30, Type_B=10, Type_A=15, Type_E=45

(ie A,B,C,D,E may not be in order)

Local set 2:

Type_C =40, Type_B=5

4,5,6….and so on will have varying types and values respectively.

Each time I have to compare universal with an individual local set and take the max. Here 1 represents universal, and I will be getting the other values sequentially. I have to take the max of each type and store it as:

Local set 1:

A=15, B=20, C=30, D=40, E=45

(D,E not present in universal so we take local set 1’s values)

Local set 2:

B=20, C=40

Which is the best datastructure in python to compute the same? Option I have considered(local setwise):

Dictionary of local sets of dictionaries of types with lists as values

{

1:{A:[10,40], B:[20,10], C:[30,30], D:[0,40], E:[0,45]},

2:{ B:[20,5], C:[30,40]

}

Please note types are actually not sequential and may get appended in any order ie A,B,C,D,E may very likely be D,A,C,B,E etc.

I would be grateful if anyone would tell me how to reference the same as well as I am new to python. (For eg, how would I access or store 40 in local set 2 of type C)

I am working with python 2.6. Thanks in advance.

jpp
  • 159,742
  • 34
  • 281
  • 339
neo_phyte
  • 9
  • 4
  • I would choose a dictionary for this. The fact your data is unordered lends itself to using `dict`. Is there any specific reason why dictionaries would not work [e.g. performance]? A general question of "are there other ways" may be too broad - usually we want to know a problem that needs solving, such as memory-consumption, performance, usability, etc. – jpp Mar 24 '18 at 21:17

1 Answers1

0

Choosing a data structure is entirely dependent on how you want to use the data. For example, if you need rapid access to named elements of your structure, then yes, a dictionary is a good choice. If you need help learning how to manipulate data structures in Python, then you should read a tutorial.

Also, please refrain from asking "can you recommend a..."-type questions on StackOverflow. Answers to those are largely opinion-based, and invite answers that won't be helpful to future SO readers.

As a side note: Why are you using Python 2.6, instead of 2.7? If you must use Python 2, 2.7 is arguably better.

Niayesh Isky
  • 1,100
  • 11
  • 17