I'm a newbie with python and I don't understand why doesn't the following work:
ea = zip([[200, 1], [10, 1]])
since I'm getting
[([200, 1],), ([10, 1],)]
while I should add an asterisk like
ea = zip(*[[200, 1], [10, 1]])
to obtain the result I want, i.e.
[(200, 10), (1, 1)]
I thought * was meant to convert the list to a tuple, what am I getting wrong?
If you have time you can read this post, it's good resource to understand how * works in Python.
The asterisk in Python unpacks arguments for a function call, please refer to here
z = [4, 5, 6]
f(*z)
will be same as:
f(4,5,6)
** in dictionary does similar work as * in list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With