Elizabeth Weiss wrote:
> words=["hello", "world", "spam", "eggs"]
> counter=0
> max_index=len(words)-1
>
> while counter<=max_index:
> word=words[counter]
> print(word + "!")
> counter=counter + 1
while 0 < 10:
get 0'th element
do something with element
increment 0 to 1
(repeat)
words[0
Steven D'Aprano at 2016/6/30 7:59:40AM wrote:
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... else: # oh no, the feared for...else!
> ... # needed to prevent the prompt overwriting the output
> .
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote:
> But there's no need to go to such effort for a mutable iterator. This is
> much simpler:
>
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... el
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote:
> I'm curious what REPL you are using, because in the vanilla Python
> interactive interpreter, the output if over-written by the prompt. That is,
> what I see in Python 3.6 is:
>
> py> nas yum yum yumpy>
>
> unless I take steps to prevent th
On 2016-06-30 09:59, Steven D'Aprano wrote:
> But there's no need to go to such effort for a mutable iterator.
> This is much simpler:
>
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... else: #
On Thu, 30 Jun 2016 01:29 am, Ian Kelly wrote:
> On Tue, Jun 28, 2016 at 11:58 AM, Grant Edwards
> wrote:
[...]
>>> But then, if you wrap up your "while" loop as a generator that yields
>>> things, you can then use it in a "for" loop which seems to me like
>>> the Pythonic way to do things. :-)
>
On Tue, Jun 28, 2016 at 11:58 AM, Grant Edwards
wrote:
> On 2016-06-28, Tim Chase wrote:
>> On 2016-06-29 01:20, Steven D'Aprano wrote:
>>> While loops are great for loops where you don't know how many
>>> iterations there will be but you do know that you want to keep
>>> going while some conditi
On Wednesday, June 29, 2016 at 1:30:04 AM UTC+12, BartC wrote:
> I don't know if that helps; I've never heard of an induction variable.
Perhaps it’s just a computability-theoretic way of saying “a variable whose
value each time round the loop is a function of its value on the previous
iteration
On 2016-06-28, Tim Chase wrote:
> On 2016-06-29 01:20, Steven D'Aprano wrote:
>> While loops are great for loops where you don't know how many
>> iterations there will be but you do know that you want to keep
>> going while some condition applies:
>>
>> while there is still work to be done:
>>
On 2016-06-29 01:20, Steven D'Aprano wrote:
> While loops are great for loops where you don't know how many
> iterations there will be but you do know that you want to keep
> going while some condition applies:
>
> while there is still work to be done:
> do some more work
I find this particul
Steven D'Aprano writes:
> While loops are great for loops
:)
Thanks, I needed the laugh.
> where you don't know how many iterations there will be but you do know
> that you want to keep going while some condition applies:
(Just keeping a bit of context so it doesn't seem like I'm laughing at
t
On Tue, 28 Jun 2016 10:36 pm, Elizabeth Weiss wrote:
> Why do we use this code if we can use the simpler for loop?
Nobody with any sense would use the more complex while loop when the for
loop does the same thing.
While loops are great for loops where you don't know how many iterations
there wil
On Tue, Jun 28, 2016 at 9:26 AM Joseph Lee
wrote:
>
> -Original Message-
> From: Michael Selik
> Sent: Tuesday, June 28, 2016 6:16 AM
>
> MS: You should not. Use the first version, it's much better. Python
> for-loops are preferable to while-loops.
>
> JL: For the most part, for loops are
On Tue, Jun 28, 2016 at 9:34 AM BartC wrote:
> On 28/06/2016 14:15, Michael Selik wrote:
> > On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss
> wrote:
> >
> >> I do not understand the second code. What is counter?
> >>
> >
> > It looks like someone wanted to make a loop induction variable.
> > ht
Elizabeth Weiss writes:
[- -]
> What I do not understand is:
>
> words=["hello", "world", "spam", "eggs"]
> counter=0
> max_index=len(words)-1
>
> while counter<=max_index:
>word=words[counter]
>print(word + "!")
>counter=counter + 1
# make it so that counter == 0
counter=0
# make i
On 28/06/2016 14:15, Michael Selik wrote:
On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote:
I do not understand the second code. What is counter?
It looks like someone wanted to make a loop induction variable.
https://en.wikipedia.org/wiki/Induction_variable
I don't know if that help
Hi,
Answers inline.
-Original Message-
From: Python-list
[mailto:python-list-bounces+joseph.lee22590=gmail@python.org] On Behalf
Of Michael Selik
Sent: Tuesday, June 28, 2016 6:16 AM
To: Elizabeth Weiss ; python-list@python.org
Subject: Re: Iteration, while loop, and for loop
On Tue
On 28/06/2016 13:36, Elizabeth Weiss wrote:
I understand this code:
words=["hello", "world", "spam", "eggs"]
for words in words
print(word + "!")
What I do not understand is:
words=["hello", "world", "spam", "eggs"]
counter=0
max_index=len(words)-1
while counter<=max_index:
word=words[c
On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss wrote:
> I do not understand the second code. What is counter?
>
It looks like someone wanted to make a loop induction variable.
https://en.wikipedia.org/wiki/Induction_variable
> Why do we use this code if we can use the simpler for loop?
>
You
19 matches
Mail list logo