L
L
leha782016-05-01 17:25:33
Python
leha78, 2016-05-01 17:25:33

How to create a multidimensional array?

rates = []
    i = 0
    for currency in tree.findall('currency'):
        rates.append([i])
        rates[i]['valuta'] = currency.find('title_alias').text

        valuta = currency.find('rates')
        # rates[i]['buy'] = valuta.find('buy_rate')
        # rates['sell'] = valuta.find('sell_rate').text
        i += 1

I'm trying to create an array so I get something like:
array = array (
usd = array (
'buy' => 2
'sell' => 3
)
eur = array (
'buy' => 2
'sell' => 3
)
}
In the view, then call like this: valuta.usd.buy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-05-01
@leha78

It looks like you came from php and are trying to apply the same model to python. There are no such arrays in python as in php, a closer one is dict. You should use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question