PDA

View Full Version : [SOLVED] Beginner python dilemma.



fxStar
July 30th, 2012, 11:38 AM
Hy there guys, i'm learning python right now and i need some help.

How do i code this in python ?


<?php

$dict = array( //first array
'product_1'=>'butter',
'product_2'=>'pasta',
'product_3'=> array('product_4'=>'PIZZA', //second one
'product_6'=> array( // third one

'product_7'=>'CHEESE'

)



)

);


var_dump($dict);

?>

Using dictionaries ? But how ?

Thx in advance and sorry for my bad english.

spjackson
July 30th, 2012, 12:55 PM
Maybe this?


#!/usr/bin/env python

dict = {
'product_1': 'butter',
'product_2': 'pasta',
'product_3': {'product_4': 'PIZZA',
'product_6': {'product_7': 'CHEESE'}}}

print(dict)
print dict['product_2']
print dict['product_3']['product_6']['product_7']

juancarlospaco
July 31st, 2012, 12:15 AM
^ spjackson do a perfect solution :)

fxStar
July 31st, 2012, 06:10 AM
In the end i managed to sort this out by myself, thank you again and problem solved.:)