Handling empty case with tuple filtering and unpacking
问题 I have a situation with some parallel lists that need to be filtered based on the values in one of the lists. Sometimes I write something like this to filter them: lista = [1, 2, 3] listb = [7, 8, 9] filtered_a, filtered_b = zip(*[(a, b) for (a, b) in zip(lista, listb) if a < 3]) This gives filtered_a == (1, 2) and filtered_b == (7, 8) However, changing the final condition from a < 3 to a < 0 causes an exception to be raised: Traceback (most recent call last): ... ValueError: need more than 0