In article <[EMAIL PROTECTED]>,
james_027 <[EMAIL PROTECTED]> wrote:
> 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? I am trying to get a value from
james_027 a écrit :
> Hi,
>
> what if we're not dealing with dict? is there a pythonic way of doing
> ternary? the bool ? x:y
Python 2.5 introduced the following syntax:
expr1 if condition else expr2
In older Python versions, one has to use and/or (like you wrongly did)
or tuple/dict dispatch
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
Hi,
what if we're not dealing with dict? is there a pythonic way of doing
ternary? the bool ? x:y
Thanks
james
--
http://mail.python.org/mailman/listinfo/python-list
james_027 <[EMAIL PROTECTED]> wrote in news:1186036331.304916.304020
@e9g2000prf.googlegroups.com:
> 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? I a
james_027 wrote:
> 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? I am trying to get a value from
> the dict, but if the key doesn't exist I will provid
james_027 wrote:
> 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? I am trying to get a value from
> the dict, but if the key doesn't exist I will provide on
On Thu, 02 Aug 2007 06:32:11 +, james_027 wrote:
> hi
>
> for example I have this dictionary
>
> dict = {'name':'james', 'language':'english'}
First of all, this is a bad name because it shadows (overwrites) the
reference to the builtin constructor, `dict`.
> value = 'sex' in dict and dic
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? I am trying to get a value from
the dict, but if the key doesn't exist I will provide one.
THanks
james
--
http://mail