Unpack a list in Python?

前端 未结 3 647
感动是毒
感动是毒 2020-11-21 23:10

I think \'unpack\' might be the wrong vocabulary here - apologies because I\'m sure this is a duplicate question.

My question is pretty simple: in a function that ex

3条回答
  •  旧时难觅i
    2020-11-21 23:41

    Since Python 3.5 you can unpack unlimited amount of lists.

    PEP 448 - Additional Unpacking Generalizations

    So this will work:

    a = ['1', '2', '3', '4']
    b = ['5', '6']
    function_that_needs_strings(*a, *b)
    

提交回复
热议问题