开发者

python style question

Is it better to pass in a zipped list of pairs, or two lists that must agree in len开发者_高级运维gth?

With two lists, I have to assert their lengths agree, but at least the parameters are named.

I am asking about the prevailing style. Are there any examples of choosing one over the other from major libraries? For example, I guess matplotlib passes in two arrays.


If your function is going to effectively zip the lists anyway, I would probably prefer to zip the lists in the caller. Then the caller can decide what to do if the lists are not the same length. Also, if your pairs are logically related then the caller might already have the data as a list of pairs, and it would be inconvenient to have to unzip it first.


In my opinion it depends on the semantics of the routine whether these checks must be done in the caller or in the callee.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜