Reputation: 993
i have this piece of simple code:
d[]-----> List of matched objects
p = []
for w in d:
if w is None:
continue
else:
q = (w.group())
p.append(q)
i have a list of macth objects that has None objects and the rest are strings
i´m trying to append the strings into a list but i´m finding it difficult with list comprehensions, specially the "continue", i tried the all() statement but with no luck:
p = [w.group() for w in d if w not None ] --- this obviously does not work
Any help will be really appreciated
Upvotes: 2
Views: 2194
Reputation: 239463
You just had to use is
operator to compare your object against None
, like this
p = [w.group() for w in d if w is not None]
But you can simply rely on the truthiness of the data in this case, like this
p = [w.group() for w in d if w]
Upvotes: 4