

def find_by_key(in_list, key, val):
    """Returns the first item with key matching val
    """
    return (item for item in in_list if item[key] == val).next()


def dict_from_list(in_list, key):
    """From a list of dicts creates a dict of dicts using a given key name
    """
    d = {}
    for entry in in_list:
        d[entry[key]] = entry
    return d



def find_by_key(in_list, key, val):
    """Returns the first item with key matching val
    """
    return next(item for item in in_list if item[key] == val)


def dict_from_list(in_list, key):
    """From a list of dicts creates a dict of dicts using a given key name
    """
    d = {}
    for entry in in_list:
        d[entry[key]] = entry
    return d

Fix compatibility with Py3 (generators no longer have next())
Fix compatibility with Py3 (generators no longer have next())

But there is a next() function as a general built-in and works in 2.6 too

  
  
  def find_by_key(in_list, key, val):
      """Returns the first item with key matching val
      """
-     return (item for item in in_list if item[key] == val).next()
+     return next(item for item in in_list if item[key] == val)
  
  
  def dict_from_list(in_list, key):
      """From a list of dicts creates a dict of dicts using a given key name
      """
      d = {}
      for entry in in_list:
          d[entry[key]] = entry
      return d
  
Fix compatibility with Py3 (generators no longer have next())
## Code Before:


def find_by_key(in_list, key, val):
    """Returns the first item with key matching val
    """
    return (item for item in in_list if item[key] == val).next()


def dict_from_list(in_list, key):
    """From a list of dicts creates a dict of dicts using a given key name
    """
    d = {}
    for entry in in_list:
        d[entry[key]] = entry
    return d

## Instruction:
Fix compatibility with Py3 (generators no longer have next())
## Code After:


def find_by_key(in_list, key, val):
    """Returns the first item with key matching val
    """
    return next(item for item in in_list if item[key] == val)


def dict_from_list(in_list, key):
    """From a list of dicts creates a dict of dicts using a given key name
    """
    d = {}
    for entry in in_list:
        d[entry[key]] = entry
    return d
