substitute for c/java's ?:

Roman Suzi rnd at onego.ru
Thu Jun 14 05:59:32 EDT 2001


On Thu, 14 Jun 2001, Glyph Lefkowitz wrote:

>On Wed, 13 Jun 2001, Neil Macneale wrote:
>
>> In article <9g5fc4$m8u$01$1 at news.t-online.com>, "Jochen Riekhof"
>> <jochen at riekhof.de> wrote:
>>
>> > I am missing something like the c/Java ?: operator.
>>
>> The ?: operator is overrated. For the time you save typing, you
>> are wasting someone else's because they need to figure out what you were
>> thinking.
>
>Trust me, this is true.  Compare the following actual examples:
>
>        public static final String aan(String s)
>        {
>                char x = s.charAt(0);
>
>                return ((( x == 'a')
>                          ||
>                         (x == 'e')
>                          ||
>                         (x == 'i')
>                          ||
>                         (x == 'o')
>                          ||
>                         (x == 'u')
>                          ||
>                         (x == 'A')
>                          ||
>                         (x == 'E')
>                          ||
>                         (x == 'I')
>                          ||
>                         (x == 'O')
>                          ||
>                         (x == 'U'))
>                          ? "an " : "a "
>                         );
>        }
>
>
>def aan(name):
>    """Utility which returns 'a' or 'an' for a given noun.
>    """
>    if string.lower(name[0]) in ('a','e','i','o','u'):
>        return 'an '
>    else:
>        return 'a '
>

Even better:

if string.lower(name[0]) in 'aeiou':
  ...

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Thursday, June 14, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Police Blotter: Energizer Bunny Charged with Battery!" _/





More information about the Python-list mailing list