0

I have two lists A,B and I am mapping the values using map() as shown below. This works fine when both the lists have elements. However, when A,B are both empty, I get an error. I also present the expected output.

A=[]
B=[]
tol=1e-12

CA, CB = map(list, zip(*((a, b) for a, b in zip(B, A) if a[0]>tol)))

print(CA)
print(CB)

The error is

in <module>
    CA, CB = map(list, zip(*((a, b) for a, b in zip(B, A) if a[0]>tol)))

ValueError: not enough values to unpack (expected 2, got 0)

The expected output is

CA=[]
CB=[]
0

1 Answer 1

1
if len(A) == 0 or len(B) == 0:
    CA = []
    CB = []
else:
    CA, CB = map(list, zip(*((a, b) for a, b in zip(A, B) if a[0] > tol)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.