You can’t remove items from a list while iterating over it. It’s much easier to build a new list based on the old one:
y = [s for s in x if len(s) == 2]
You can’t remove items from a list while iterating over it. It’s much easier to build a new list based on the old one:
y = [s for s in x if len(s) == 2]