1

Having the call

set(self.oid_to_path(oid, entries_parents) for oid in modified_by_one_parent_oids)

this works, but also adds None to the list if the function returns None

So modifying it to

set(self.oid_to_path(oid, entries_parents) for oid in modified_by_one_parent_oids if None != self.oid_to_path(oid, entries_parents))

also works, without the Nones.

However this has the drawback of calling the function twice. How to call it only once, and use some memoization instead?

1 Answer 1

3

Use a set comprehension on a generator expression...

g = (self.oid_to_path(oid, entries_parents) for oid in modified_by_one_parent_oids)
result = {el for el in g if el is not None}

Please note that you don't actually have a list comprehension in your code. You're calling the set constructor with a generator expression, which can be done simpler – with a set comprehension, as shown above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.