0

I want to join two lists of dictionaries on a single key, and I saw the following answer to use zip_longest in Python 3.5+. In my case is the same as the question join two lists of dictionaries on a single key.

However, I failed to find how efficient is this method. If I'll use it for long lists, should it work well?

martineau
  • 119,623
  • 25
  • 170
  • 301
ChikChak
  • 936
  • 19
  • 44
  • Should be easy to test with the `timeit` module. – Klaus D. Jun 30 '21 at 13:19
  • @KlausD: `timeout` does not determine time complexity — merely how long something took to execute. – martineau Jun 30 '21 at 13:46
  • @martineau Well, isn't that the value you are interest in if you are talking about time complexity? Of cause you have to do it multiple times with reasonable sample sizes. – Klaus D. Jun 30 '21 at 13:48
  • @KlausD: No, it's the computational complexity that describes the amount of computer time it takes to run an algorithm, usually with respect to the size of its input, and is expressed in "Big O" notation (not execution time or rate of processing per unit of time). See @ Faboor's answer. Also see the [Wikipedia article](https://en.wikipedia.org/wiki/Time_complexity) on the subject. – martineau Jun 30 '21 at 14:03

1 Answers1

1

zip_longest will create an iterator over the longest list. So if you you then consume it all it will be O( length_of_longest_list )

Whether the process of merging the dicts like that is efficient is an entirely different question :)

Faboor
  • 1,365
  • 2
  • 10
  • 23