#!/usr/local/bin/python3 dirnames = ['1','2','_3','4','5','6','7','8','_9','0'] for i in range(100000): i = 0 dir_count = len(dirnames) while i < dir_count: if dirnames[i].startswith('_'): del dirnames[i] dir_count -= 1 continue i += 1 print(dirnames)