[issue44952] list need to filter again because the continue empty str value?

Steven D'Aprano report at bugs.python.org
Thu Aug 19 00:36:06 EDT 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Not a bug. Use this instead:

def rv(items):
    for item in items[:]:  # iterate over a copy
        if not (item.isspace() or item == ''):
            items.remove(item)
    return items


Or the same as above, as a list comprehension, no need to make a copy:

items = [item for item in items if not (item.isspace() or item == '')]

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44952>
_______________________________________


More information about the Python-bugs-list mailing list