Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

If I have lists like these:

transactions = ['001','002','003']

transaction_dates = ['01-01-2019','01-02-2019','01-03-2019']

transaction_amounts = ['27.00','35.00','36.00']

And I use zip like this

results = zip(transactions,transaction_dates,transaction_amounts)

How do I tell if results is empty?

1 Answer

0 votes
by (25.1k points)

Since zip will return an iterator you can just use the next method to iterate over the zipped item and if it leads to StopIteration exception then it indicates that the list is empty like this:

def is_empty(items):

    try:

    next(items)

    return False

    except StopIteration:

    return True

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)
0 votes
2 answers
asked May 30, 2019 in Python by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked May 14, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...