def lol_tuples(head, ind, values, dummies):
 if (not ind):
  return head
 if (ind[0] not in dummies):
  return lol_tuples((head + (values[ind[0]],)), ind[1:], values, dummies)
 else:
  return [lol_tuples((head + (v,)), ind[1:], values, dummies) for v in dummies[ind[0]]]

def lol_tuples ( head , ind , values , dummies ) : if ( not ind ) : return head if ( ind [ 0 ] not in dummies ) : return lol_tuples ( ( head + ( values [ ind [ 0 ] ] , ) ) , ind [ 1 : ] , values , dummies ) else : return [ lol_tuples ( ( head + ( v , ) ) , ind [ 1 : ] , values , dummies ) for v in dummies [ ind [ 0 ] ] ]
list of list of tuple keys parameters head : tuple the known tuple so far ind : iterable an iterable of indices not yet covered values : dict known values for non-dummy indices dummies : dict ranges of values for dummy indices examples .