Why does this nested list comprehension generate an error?
conn_request, weights = zip(*[
((conn, request), request[2])
for conn in unchoked_conns
for request in conn.peer_requests
])
Generates:
for conn in unchoked_conns
ValueError: need more than 0 values to unpack
I cannot work out what I'm doing wrong. I thi开发者_运维技巧nk it has some thing to do with the dependence of request
on conn
?
>>> a, b = zip(*[])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 0 values to unpack
Your LC produces an empty list. Try verifying that unchoked_conns
has any elements.
zipping an empty list returns a single empty list, hence the assignment fails. That is consistent with the zip help, which clearly says:
The returned list is truncated in length to the length of the shortest argument sequence
In your case, the shortest argument sequence has length 0.
精彩评论