I have three lists that I want to iterate on with an index. For that, I tried to use enumerate(zip(x, y, z))
, but when I try to unpack that, it fails
[f.write('mVtet0.row({}) = Eigen::Vector3d({}, {}, {})\n'.format(i, x,y,z) for i, x, y, z in enumerate(zip(x,y,z))]
Gives the following error: ValueError: not enough values to unpack (expected 4, got 2)
I understand the issue, enumerate creates a tuple with the index and the result of the zip. What is the correct way to unpack everything?
you get int
and a tuple
. Enclose x, y, z in brackets to make it tuple
.
[f.write('mVtet0.row({}) = Eigen::Vector3d({}, {}, {})\n'.format(i, x,y,z)
for i, (x, y, z) in enumerate(zip(x,y,z))]
That said, in my opinion this is abuse of list comprehension with sole purpose to make it one-liner. Better use regular loop - it will be way more readable. And also better use f-strings.
for i, (x, y, z) in enumerate(zip(x,y,z)):
f.write(f'mVtet0.row({i}) = Eigen::Vector3d({x}, {y}, {z})\n')
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