On 9/13/2012 9:15 AM, Masklinn wrote:
> attrgetter and itemgetter are both very useful functions, but both haveThis seems like a plausible idea. The actual C version requires one
> a significant pitfall if the arguments passed in are validated but not
> controlled: if receiving the arguments (list of attributes, keys or
> indexes) from an external source and *-applying it, if the external
> source passes a sequence of one element both functions will in turn
> return an element rather than a singleton (1-element tuple).
> This means such code, for instance code "slicing" a matrix of some sort
> slicer = (operator.itemgetter(*indices) if len(indices) > 1
> This makes for more verbose and less straightforward code, I think it
> # works the same no matter what len(indices) is
> which in the example equivalences would be an override (to False) of
> The argument is backward-compatible as neither function currently
> Uncertainty note: whether force_tuple (or whatever its name is)
argument. The Python equivalent in the doc does not (hence the different
signature), as it would return an empty tuple for empty *items.
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.