0

I'm trying to figure out if I should make my output a list or dictionary? Which one would be easy to verify when you are trying to match 3 different outputs with millions of lines?

I'm going to take two different outputs and verify three pieces for each line. Problem is, later I'll have a output C which I want to try and verify again output A and B. I'm leaning towards a dictionary?

For example: (bold is what I'll be matching

output A: 10.1.1.1:80 10.2.1.1:81 10.1.1.1:80 10.3.1.1:81 etc etc etc name ... ... ...

output B: name etc etc etc etc 10.1.1.1/16 10.2.1.1/16 ... ... ...

  • Welcome to SO. Please see the help article [How to ask a good question](https://stackoverflow.com/help/how-to-ask). – Arya McCarthy Apr 21 '17 at 18:50
  • If you need to check if an element is included in an iterable, it's a good idea to use a `dict` or a `set` instead of a `list`, especially if you have millions of elements. – Eric Duminil Apr 21 '17 at 18:56
  • Great thanks! So with all those lines to match up, a dict would be good? Anyone know what modules would be the best to use if I'm trying to find the 3 things with output A & B? – user3203920 Apr 21 '17 at 19:13

1 Answers1

0

I'm trying to figure out if I should make my output a list or dictionary? Which one would be easy to verify when you are trying to match 3 different outputs with millions of lines?

They key difference between a list and a dictionary is the way you access your data. For a dictionary, you will be using keys, where for lists you would be using a sequence of indexes to glean your data. Which one should you use here? This is sometimes a performance issue and sometimes it's about code clarity. I don't think the latter issue relates to your case, I think performance would be your greatest asset here, that's because you're dealing with dozens of lines to be processed and matched.There has been many internal optimizations for Python objects, so it's better to focus on what you're trying to achieve instead of focusing on objects. I could very easily recommend dictionaries, but would that be a good recommendation for later developments in your code? I don't know, unless we work on that specific code any recommendation would be vague.

If you care about performance, this might help:

Python: List vs Dict for look up table

GIZ
  • 4,409
  • 1
  • 24
  • 43