1

I have a function, that needs to be python 2.6 conform:

def find(entity, **kwargs):
    return instance.search(
        set(),
        {'search': '{0}="{1}"'.format(key, kwargs[key]) for key in kwargs}
    )

However a python 2.6 sanity checks fails at character position 59, which is the "for" from the loop. Are inline loops not ok in python 2.6?

Mosfet
  • 33
  • 5
  • true, that is a duplicate. since I did not know where the problem lay, I could sadly not find that one. – Mosfet May 29 '17 at 11:22

1 Answers1

1

Dictionary comprehension was introduced in Python 2.7. See PEP 274 -- Dict Comprehensions.

You can instead construct the dictionary by calling dict on a generator expression of keys and values:

def find(entity, **kwargs):
    return instance.search(
        set(),
        dict(('search', '{0}="{1}"'.format(key, kwargs[key])) for key in kwargs)
    )

However, note that your dictionary will only contain a single key and value since search is the only key you've provided and it's not changing across the gen. exp.

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139