-1

What is the difference between these two calls? How does the second example syntax works ? how valid is using colon : in second example ?

   with concurrent.futures.Executor() as executor:
      futures = {executor.submit(perform, task) for task in get_tasks()}

and

 with concurrent.futures.Executor() as executor:
    futures = {executor.submit(perform, task): task for task in get_tasks()}

Would you give me some more example regarding using colon in set comprehension ? regards

Amir
  • 194
  • 1
  • 7

1 Answers1

2

The first example is a set comprehension, the second is a dictionary comprehension.

numbers = [1, 2, 2]
set_comp = {n for n in numbers}
dict_comp = {index: value for index, value in enumerate(numbers)}

print(set_comp, dict_comp)

Output:

{1, 2}
{0: 1, 1: 2, 2: 2}
Tomer Ariel
  • 1,397
  • 5
  • 9