Python Array
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Mar 31 01:56:36 EDT 2016
On 31/03/2016 06:34, tdsperth at gmail.com wrote:
> I am creating the following
>
> aData = []
This is a Python list, not an array as the subject gives.
>
> # get my data from database
>
> for row in rows:
> aData.append({row["tierid"]:"name":row["tiername"],"description":row["tierdesc"],"option":row["tieroption"],"price":str(row["tierprice"])}})
Please cut and paste your code, don't try to type it in. The above
gives a syntax error at the second colon, which should presumably be a
comma.
>
> when I display the output the order the data was entered is not what is displayed
>
> {'BBS': {'option': 'Small', 'description': 'Broadband Bundle', 'name': 'Broadband', 'price': '179.00
> {'BBM': {'option': 'Medium', 'description': 'Broadband Bundle', 'name': 'Broadband', 'price': '215.0
> {'BBL': {'option': 'Large', 'description': 'Broadband Bundle', 'name': 'Broadband', 'price': '295.00
>
> as you can see the option element was added third but is the first one displayed.
>
> Is this just standard - I am using Python 3.5
Yes, as you are using a standard dict within the list. There is
https://docs.python.org/3/library/collections.html#collections.OrderedDict
which retains the insertion order.
>
> Regards
>
> Colin
>
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list