liveBook · Manning

Key function

A key function is a callable that maps an item to a value used to compare, order, identify, index, or match it.

How 2 Manning books explain it

D3.js in Action, Third Edition

A key function computes stable identity keys that allow data-bound elements to be matched with corresponding data items across updates.

How it is used
Maintains stable data-element identity while filtering an interactive D3 scatterplot.
How deep it goes
Explains positional matching, uid-based matching, and integration with D3 data() and join(), without descending into API internals.
Examples
Uses filtered cetacean circles keyed by uid and compares D3 matching with React list keys.
What you can do after
Apply it via D3's data() method to preserve element identity during dataset updates and control resulting selections.

Read how D3.js in Action, Third Edition explains key function →

The Quick Python Book, Fourth Edition

A key function is a callable that maps each item to a value used to determine that item's ordering during sorting.

How it is used
Customizes sorting when default comparison does not match the desired ordering.
How deep it goes
Explains the one-argument return rule, named and lambda syntax, applications, and repeated-call performance cost.
Examples
Demonstrates sorting words by length, text case-insensitively, or by a substring of each line.
What you can do after
Apply it via Python sorting methods to order items by a computed property.

Read how The Quick Python Book, Fourth Edition explains key function →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.