# Tai Sakuma <tai.sakuma@gmail.com>
import itertools

##__________________________________________________________________||
def convert_key_vals_dict_to_tuple_list(dict_, fill=float('nan')):

    d = [ ]

    if not dict_: return d

    vlen = max([len(vs) for vs in itertools.chain(*dict_.values())])

    for k, vs in dict_.items():
        try:
            d.extend([k + tuple(v) + (fill, )*(vlen - len(v)) for v in vs])
        except TypeError:
            # assume k is not a tuple
            d.extend([(k, ) + tuple(v) + (fill, )*(vlen - len(v)) for v in vs])


    return d

##__________________________________________________________________||

@@ -158,21 +158,29 @@
 le_list(
+key_vals_
 dict
-_
 , fill=f
@@ -198,17 +198,26 @@
 ):%0A%0A    
-d
+tuple_list
  = %5B %5D%0A%0A
@@ -227,21 +227,29 @@
  if not 
+key_vals_
 dict
-_
 : return
@@ -249,17 +249,26 @@
  return 
-d
+tuple_list
 %0A%0A    vl
@@ -312,21 +312,29 @@
 .chain(*
+key_vals_
 dict
-_
 .values(
@@ -356,21 +356,29 @@
 , vs in 
+key_vals_
 dict
-_
 .items()
@@ -396,33 +396,42 @@
 ry:%0A            
-d
+tuple_list
 .extend(%5Bk + tup
@@ -553,17 +553,26 @@
         
-d
+tuple_list
 .extend(
@@ -643,17 +643,26 @@
  return 
-d
+tuple_list
 %0A%0A##____

rename arg, var in convert_key_vals_dict_to_tuple_list()