Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79024

Re: while loop - multiple condition

Date 2014-10-12 15:42 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: while loop - multiple condition
References (2 earlier) <loom.20141012T191849-946@post.gmane.org> <CAPTjJmouQsm_9ccqdtmJ3kmd4SqmmOqk3OVdS4mngeHaVT2S6w@mail.gmail.com> <loom.20141012T195709-937@post.gmane.org> <mailman.14798.1413137019.18130.python-list@python.org> <878uklcd3r.fsf@elektro.pacujo.net>
Newsgroups comp.lang.python
Message-ID <mailman.14805.1413146405.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-10-12 22:16, Marko Rauhamaa wrote:
> is equivalent with
> 
>     while ans.lower()[0] != 'y':
>          ans = input('Do you like python?')

And still better improved with

  while ans[:1].lower() != 'y':
    ans = input('Do you like python?')

in the event that len(ans)==0 (a situation which will crash the
various current examples).

It also only expends the effort to lowercase 0-or-1 characters,
rather than lowercasing an entire string just to throw away
everything except the first character.

-tkc


Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 05:03 +1100
  Re: while loop - multiple condition Marko Rauhamaa <marko@pacujo.net> - 2014-10-12 22:16 +0300
    Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 06:22 +1100
    Re: while loop - multiple condition Tim Chase <python.list@tim.thechases.com> - 2014-10-12 15:42 -0500
      Re: while loop - multiple condition Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-13 09:56 +1100
        Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:12 -0700
          Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 09:26 -0700
            Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:43 -0700
              Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 10:12 -0700
                Re: while loop - multiple condition Michael Torrie <torriem@gmail.com> - 2014-10-13 16:08 -0600
                Re: while loop - multiple condition wxjmfauth@gmail.com - 2014-10-13 23:34 -0700
      Re: while loop - multiple condition giacomo boffi <pecore@pascolo.net> - 2014-10-15 01:04 +0200
        Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-15 10:16 +1100

csiph-web