本文整理汇总了Python中toolz.itertoolz.join函数的典型用法代码示例。如果您正苦于以下问题:Python join函数的具体用法?Python join怎么用?Python join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_join_missing_element
def test_join_missing_element():
names = [(1, 'one'), (2, 'two'), (3, 'three')]
fruit = [('apple', 5), ('orange', 1)]
result = set(starmap(add, join(first, names, second, fruit)))
expected = set([((1, 'one', 'orange', 1))])
assert result == expected
示例2: test_join
def test_join():
names = [(1, 'one'), (2, 'two'), (3, 'three')]
fruit = [('apple', 1), ('orange', 1), ('banana', 2), ('coconut', 2)]
def addpair(pair):
return pair[0] + pair[1]
result = set(starmap(add, join(first, names, second, fruit)))
expected = set([((1, 'one', 'apple', 1)),
((1, 'one', 'orange', 1)),
((2, 'two', 'banana', 2)),
((2, 'two', 'coconut', 2))])
assert result == expected
result = set(starmap(add, join(first, names, second, fruit,
left_default=no_default2,
right_default=no_default2)))
assert result == expected
示例3: test_join_double_repeats
def test_join_double_repeats():
names = [(1, 'one'), (2, 'two'), (3, 'three'), (1, 'uno'), (2, 'dos')]
fruit = [('apple', 1), ('orange', 1), ('banana', 2), ('coconut', 2)]
result = set(starmap(add, join(first, names, second, fruit)))
expected = set([((1, 'one', 'apple', 1)),
((1, 'one', 'orange', 1)),
((2, 'two', 'banana', 2)),
((2, 'two', 'coconut', 2)),
((1, 'uno', 'apple', 1)),
((1, 'uno', 'orange', 1)),
((2, 'dos', 'banana', 2)),
((2, 'dos', 'coconut', 2))])
assert result == expected
示例4: test_key_as_getter
def test_key_as_getter():
squares = [(i, i**2) for i in range(5)]
pows = [(i, i**2, i**3) for i in range(5)]
assert set(join(0, squares, 0, pows)) == set(join(lambda x: x[0], squares,
lambda x: x[0], pows))
get = lambda x: (x[0], x[1])
assert set(join([0, 1], squares, [0, 1], pows)) == set(join(get, squares,
get, pows))
get = lambda x: (x[0],)
assert set(join([0], squares, [0], pows)) == set(join(get, squares,
get, pows))
示例5: test_outer_join
def test_outer_join():
result = set(join(identity, [1, 2], identity, [2, 3],
left_default=None, right_default=None))
expected = set([(2, 2), (1, None), (None, 3)])
assert result == expected