Serhiy Storchaka added the comment: It is safe to modify a sequence during iteration if it's size not increased.
>>> words = ['cat', 'window', 'defenestrate'] >>> for i, w in enumerate(words): ... if len(w) > 6: ... words[i] = w[:5] + '…' ... >>> words ['cat', 'window', 'defen…'] ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16225> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com