jeudi 17 août 2017

How to put if/else statements in list comprehension along with multiple supporting expressions

How can i convert this kind of loops into list comprehension.

temp = []
for x in email_data:
    data = Apply_Filters(x[0])
    if len(data.split()) > 1:
        email_data2.append(tuple([x[1], data]))
        temp.append(data)

So far my search got me to the comprehensions with only if else statements without performing any other functions like .

[y if y not in b else other_value for y in a]

But i first have to apply a function to a looping variable and then have to use conditional structure.

Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire