python: combination of lists in dict, with various size of list -


There may be different lanes (including empty) in the five parameters. I wrote a long code for the first three parameters, for this, iterative for larger code with more duplication for more parameters. How to code at least?

  params1 = [1,2] Paramos 2 = [] Params 3 = [3,4,5,6] # ... Parameters 5 = [7,8] for # 3 Parameters Example: Summary = {} if 0 & lt; Lane (parameter 1): Parameter1 in parameter1: Summary ['param1'] = Ultimate 1 if 0 & lt; Lane (paragraph 2): Paramus 2 in param2: Summary ['Ultimate 2'] = Ultimate 0 if 0 & lt; Lane (Param 3): For Param3 in Param 3: Summary ['param3'] = param2 Print Summary Second: Print Summary Second: If 0 & lt; Lane (Param 3): For Param3 in Param 3: Summary ['param3'] = param2 Print Summary Second: Print Summary Second: If 0 & lt; Lane (paragraph 2): Paramus 2 in param2: Summary ['Ultimate 2'] = Ultimate 0 if 0 & lt; Lane (paragraph 3): For Param3 in Param 3: Summary ['Ultimate 3'] = Ultimate Print Print Balance: Print Summary Second: If 0 & lt; For param3 in paragraph 3: Summary ['param3'] = param6 Print summary Second: Print summary  

There is no need to get a dictionary with combinations, empty parameters, for example code Production: <3 ': 3,' Param 1 ': 1} {' Param 3 ': 4,' Param 1 ': 1} {' Param 3 ': 5,' Param 1 ': 1} { {'Param 3': 3, 'param1': 2} {'param 3': 4, 'param 1': 2} {'param 3': 5, 'param1': 6, 'param1': 1} 'Param 1': 2} <'Param3': 6, 'param1': 2}

How to change the code in small lines?

You can do this using recursive:

  def Affich (Params, Summary = None): # Print (Params, Summary) If Lane (Param) == 0: Print Summary Second: If the summary is none: abstract = {} name, purse = PARAM [0] if LAN (Purse [1:], summarized) (aprich ('params 1', [1, 2]), ('Paramos 2', []), ('Params 3', [3, 4, 5, 6]), ('Param 5', [7, 8])  

returns:

  

Comments