I am trying to create a set that contains all the results as returned by a function which is applied to each element in a set. The following code snippet hopefully clarifies:
results = set()
for node in nodes:
results = set.union(results, foo(node))
Although the code accomplishes what I want, I am sure it can be rewritten much better and more concise. As I have to repeat this construct several times, any help is much appreciated.
Thanks in advance.
or
If
nodescan be empty, then use this to make sure it doesn’t throw an exception: