![]() ![]() I have expected values from a to go in xp, values from b to go in yp, and values from c to go in m. What you're saying here, though, is that it's about four sets being unpacked into three variables. What I took from bowlofred was the "too many items to unpack" Traceback referred to a total of 12 items trying to be unpacked into 3 variables. ![]() The Python for doing that is: x = list(zip(a, b, c))And I could then iterate over the tuples in x. When I first read you post I thought you were trying to transpose this group of lists: Quote:a = 4 items cannot be unpacked into 3 variables (well, they can, but you know what I mean). Unpacking puts the first item in x, the second in y, and the two remaining items in z. zip(a, b, c) will produce 4 values before raising the StopIteration exception. Output:('1-6-2017', 265, 'd') ('1-13-2017', -10, '') I told Python that z will take all remaining values from the iterator, and when printing you can see that z contains two values, not one. I have three (a, b, c) being unpacked to three (xp, yp, m). What would be problematic would be trying to unpack 4 variables to 3 or 5 to 3 or any unequal number. There would be 4 groupings of 3 elements, but I thought number of groupings would be inconsequential as any could be accommodated. My thinking was that this would unpack the lists one element at a time and put the a component in xp, the b component in yp, and the c component in m. Zip(, ) => (1,5), (2,6), (3,7), (4,8) # 4 elements.ĭescribe more what you want those variables to contain, but looping over a zip is pretty natural. I can't tell from your program if you mean for xp to have the first "set" from the zip or if you expected it to have the "a" portion. This means if you try to assign it to (xp, yp, m), it will complain that 4 elements can't fit into 3 variables. You can loop over that iterator to get the elements, or you can assign all the elements.īut since you hand your zip iterables that all have 4 elements, your zip iterator will also have 4 elements. (Mar-24-2022, 07:41 PM)bowlofred Wrote: Zip returns an iterator. ![]()
0 Comments
Leave a Reply. |