SQL-style joins for Python iterables.

Use

join does the work of associating iterable items together, but gives you all the power for customization, letting you supply your own join function, separate keys for left and right iterables, and even letting you use functions instead of attribute names.

merge used above, for example, is join using an object union to join matched objects. You can use a tuple join, which is default for join :

>>> join ( cats , dogs , key = 'name' , join_fn = tuple_join ) [( Cat ( name = 'gatsby' , meow = 'rowr' , weight = 15 ), Dog ( name = 'gatsby' , woof = 'Rruff!' , weight = 16 ))]

Supplying your own join function is easy:

>>> def weight_sum ( left , right ): ... return left . weight + right . weight ... >>> join ( cats , dogs , key = 'name' , join_fn = weight_sum ) [ 31 ]

Using separate key functions is easy too: