如果我有这样的列表:
transactions = ['001','002','003']
transaction_dates = ['01-01-2019','01-02-2019','01-03-2019']
transaction_amounts = ['27.00','35.00','36.00']
我这样使用zip
results = zip(transactions,transaction_dates,transaction_amounts)
如何确定results
是否为空?
答案 0 :(得分:2)
对于此特定任务,建议您定义一个函数并调用由next
返回的迭代器的zip
方法,并用try
/ expect
包裹以捕获{ {1}}警告:
StopIteration
def is_empty(i):
try:
next(i)
return False
except StopIteration:
return True