Asterisk in function call

前端 未结 3 2188
渐次进展
渐次进展 2020-11-22 17:28

I\'m using itertools.chain to \"flatten\" a list of lists in this fashion:

uniqueCrossTabs = list(itertools.chain(*uniqueCrossTabs))

how is

3条回答
  •  生来不讨喜
    2020-11-22 17:43

    It splits the sequence into separate arguments for the function call.

    >>> def foo(a, b=None, c=None):
    ...   print a, b, c
    ... 
    >>> foo([1, 2, 3])
    [1, 2, 3] None None
    >>> foo(*[1, 2, 3])
    1 2 3
    >>> def bar(*a):
    ...   print a
    ... 
    >>> bar([1, 2, 3])
    ([1, 2, 3],)
    >>> bar(*[1, 2, 3])
    (1, 2, 3)
    

提交回复
热议问题