[Steven D'Aprano <steve@pearwood.info>] wrote:
values = take(count, items, default=None)
[MRAB]
Why is the count first? Why not have the (definitely required) items first and let the count have a default of 1?
[Steven]
I lifted the bulk of the function, including the signature, from the recipe in the itertools documentation.
I suspect the reason the recipe specifies the count first is because that follows the standard order in English:
"take two of the eggs"
rather than "take eggs two of".
Part of it, but I believe it's more following prior art, like Haskell's take: http://zvon.org/other/haskell/Outputprelude/take_f.html In that language, the case for putting the count first is overwhelming: all functions in Haskell take a single argument, and currying is ubiquitous. Being able, e.g., to write take3 = take 3 to get a function that returns the first 3 elements of whatever that function is applied to is far more useful, e.g., than being able to write take_from_x = take x to get a function such that `take_from_x n` returns the first `n` elements of `x`. The same follows in a weaker way in Python via fans of functools.partial