#!/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)