Apr-27-2019, 04:31 AM
Hi All,
I learning Python and I see that my knowledge of this language is very poor as I am trying to translate a function from PHP to Python but I cannot get results.
This is the code in PHP and below, my try in Python,
MY TRY IN PYTHON
__________________
Thanks a lot in advance.
Mapg
I learning Python and I see that my knowledge of this language is very poor as I am trying to translate a function from PHP to Python but I cannot get results.
This is the code in PHP and below, my try in Python,
__________________ PHP Code __________________ function getCombinations($arrays) { $result = array(array()); foreach ($arrays as $property => $property_values) { $tmp = array(); foreach ($result as $result_item) { foreach ($property_values as $property_value) { $result_item[$property] = $property_value; $tmp[] = $result_item; } } $result = $tmp; } return $result; } $combinations = getCombinations( array( 'item1' => array('A', 'B'), 'item2' => array('C', 'D'), 'item3' => array('E', 'F'), ) ); var_dump($combinations);__________________
MY TRY IN PYTHON
__________________
def getCombinations(arrays): result = [] for property, property_values in arrays.items(): tmp = [] for result_item in result: for property_value in property_values: result_item[property] = property_value tmp.append(result_item) result = tmp return resultMy intention is to learn where are my faults to continue learning.
Thanks a lot in advance.
Mapg