#!/usr/local/bin/python3 dirnames = ['_1','2','_3','4','_5','6','_7','8','_9','0']*10 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 else: i += 1 print(dirnames)