namesStations = [] completeList = [] with open('listeBhfe') as doc: for line in doc: completeList.append(line.split()) for array in completeList: if array[-1][0] == '(' and array[-1][-1] == ')': namesStations.append(array) namesList = [] for namearray in namesStations: if len(namearray) < 4: namesList.append(' '.join(namearray[0:-1])) print(namesList)