jeudi 25 mai 2017

Making a single-line 'if' statement without an 'else' in Python 3

Is there any way to do this in a single line, but without using a 'None'?:

folders = ['Project 1', 'Project 2']
files = os.listdir('/home/stavros/Documents/Python')
for i in files:
    files.remove(i) if i in folders else None

Could one 'skip' the 'else' statement?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire