james_027 a écrit : > hi > > for example I have this dictionary > > dict = {'name':'james', 'language':'english'} > > value = 'sex' in dict and dict['sex'] or 'unknown' > > is a right pythonic of doing this one?
No. The first problem is that using 'dict' as an identifier, you're shadowing the builtin dict type. The second problem is that you're reinventing the square wheel. > I am trying to get a value from > the dict, but if the key doesn't exist I will provide one. d = {'name':'james', 'language':'english'} d.get('sex', 'unknown') -- http://mail.python.org/mailman/listinfo/python-list