generating a full combination of values from multiple lists in python?
Question: I would like to generate a full-matrix of value combinations from multiple
lists. But I don't always know how many lists will be provided, and each one
can have a different length. I was able to get the answer by abusing
itertools.product(), but I think it's overkill. Is there a more pythonic way?

    
    
    import itertools
    
    listoflists = [
       ["happy","sad"],
       ["car","bike","truck"],
       ["true","false"],
       [3,6,34,8,31]]
    
    def comboGenerator(lol):
    
      # create a uniform N-dimensional struct, big enough to hold longest dimension
      longest = max(map(lambda x: len(x),lol))
      superstruct = itertools.product(range(longest), repeat=len(lol))
    
      # visit each cell in the struct, ignore the empty ones
      for a in superstruct:
        combo = []
        try:
          for index in range(len(lol)):
            combo.append(lol[index][a[index]])
          yield (combo)
        except IndexError:  #this was an empty cell; try again
          pass
    
    for x in comboGenerator(listoflists):
      print (x)
    


Answer: 
    result = list(itertools.product(*listoflists))
    

if you want the element type of `result` list be a `list`, then convert it by:

    
    
    result = [list(item) for item in result]
    

