Python style question

Is it better to pass in a zip list of pairs or two lists that should be consistent in length?

With two lists, I have to argue that their lengths are consistent, but at least the parameters are called.

I ask about the prevailing style. Are there any examples of choosing one of them from large libraries? For example, I assume that matplotlib runs in two arrays.

+3
source share
2 answers

If your function would effectively button lists anyway, I'd rather pick lists in the caller. Then the caller can decide what to do if the lists do not have the same length. In addition, if your pairs are logically connected, then the caller may already have data as a list of pairs, and it would be inconvenient to unpack it first.

+4
source

In my opinion, it depends on the semantics of the subroutine whether these checks should be performed on the calling or called party.

+4
source

Source: https://habr.com/ru/post/1792306/


All Articles