0

I have generator with 3 pretty big chunks. I am creating combinations of 2 elements from it, but then in some part of code I need third part (the one not included in combinations). How should I do it? I don't need the simplest or the prettiest solution, I need the fastest solution possible.

Example:

a = ['a','b','c']
gen = chunks(a, 2) # this is not important
for x in combinations(gen, 2):
    # let's say we have x = ['a','b'] and I want to get 'c'
    # I know it is possible to put all generator elements in list and get 'c' 
    # with for loop or set, but I don't if this is the fastest way to get it
thecoparyew
  • 715
  • 1
  • 9
  • 24

1 Answers1

0

As an efficient way i suggest define a function that you could use it multitime and get the difference with set because its a pythonic and fast way :

>>> def diff(test_array=[],main_array=['a','b','c']):
...  return set(main_array).difference(set(test_array)).pop()
... 
>>> diff(['a','b'])
'c'
Mazdak
  • 105,000
  • 18
  • 159
  • 188