On 2015-10-22 14:50, Thomas C. Hicks wrote:
On 10/23/2015 05:19 AM, jarod_v6--- via Tutor wrote:
Hi!!I would like to prepare a dictionary with complex structure:

complex = {name ="value",surname="po",age=poi)
What is the most pythonic way to build a dictionary of dictionary?thanks for any help!

This doesn't look too complex so I am probably missing something.

The normal dictionary construction would look something like this:

    mydict = dict('name'='value', 'surname'='po','age'='poi')

Then you can access any given item in mydict with the get method:

    mydict.get('name')

SDG,

tom

alex@x301:~$ python3
Python 3.4.3 (default, Jul 28 2015, 18:24:59)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
mydict = dict('name'='value', 'surname'='po','age'='poi')
  File "<stdin>", line 1
SyntaxError: keyword can't be an expression


my understanding is that you could have done it in either of the following two ways:
1:    mydict = dict(name='value', surname='po',age='poi')
2:    mydict = {'name': 'value', 'surname': 'po','age': 'poi'}

Also, accessing any given item might be done as follows:
mydict['name']
rather than calling the get method, n'est pas?


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to