• sugar_in_your_tea@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    3 days ago

    Oh, there are plenty of other terrible ways:

    for _ in mylist:
        break
    else:
        # whatever you'd do if mylist was empty
    
    if not any(True for _ in mylist):
    
    try:
        def do_raise(): raise ValueError
    
        _ = [do_raise() for _ in mylist]
    except ValueError:
        pass
    else:
        # whatever you'd do i mylist was empty
    

    I could probably come up with a few others as well.

    Please note that none of these handles the TypeError if mylist is None.