Простой рекурсивный чек будет достаточно и будет возвращаться как можно раньше, мы предполагаем, что он не является списком или содержит не-списки, он не пуст
def isEmpty (alist) : try: for a in alist: if not isEmpty (a): return False, за исключением: # мы будем здесь, если alist не является возвратом итератора / списка False return True alist = [] blist = [alist] # [[]] clist = [alist, alist, alist] # [[], [], []] dlist = [blist] # [[[]]] elist = [1, isEmpty, dlist] if isEmpty (alist): print "alist «is empty» if isEmpty (dlist): print «dlist is empty», если не isEmpty (elist): print «elist is not empty»
Вы можете дополнительно улучшить его, чтобы проверить рекурсивный список или нет объектов списка, или может быть пустым dicts и т. д.
Это аргумент quit()
. См. ?quit
.
Аргументы :
status: the (numerical) error status to be returned to the operating
system, where relevant. Conventionally ‘0’ indicates
successful completion.
Подробности :
Some error statuses are used by R itself. The default error
handler for non-interactive use effectively calls ‘q("no", 1,
FALSE)’ and returns error code 1. Error status 2 is used for R
‘suicide’, that is a catastrophic failure, and other small numbers
are used by specific ports for initialization failures. It is
recommended that users choose statuses of 10 or more.
quit(status=1)
Заменить 1
любым кодом выхода, который вам нужен.
quit(save = "no", status = 1, runLast = FALSE)
– Fernando Correia 27 November 2014 в 01:00