![]() |
itertools and chain - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: itertools and chain (/thread-8458.html) |
itertools and chain - mp3909 - Feb-21-2018 Hi, Can someone please help me understand what is the difference between this t = list(itertools.chain(*([1,2,3],[4,5,6]))) and y = list(itertools.chain(([1,2,3],[4,5,6]))) .The first one gives this result [1,2,3,4,5,6] whilst the second one gives a list of lists i.e. [[1,2,3],[4,5,6]]
RE: itertools and chain - Larz60+ - Feb-21-2018 That's the difference! RE: itertools and chain - snippsat - Feb-21-2018 * take function argument and expands it into actual positional arguments in the function call.def bar(seq, a=None, b=None): print(seq, a, b) >>> bar([1, 2, 3]) [1, 2, 3] None None >>> bar(*[1, 2, 3]) 1 2 3 |