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


Groups > comp.lang.python > #109216

Re: why for loop print only once after add if statement

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: why for loop print only once after add if statement
Date 2016-05-28 12:59 -0400
Organization IISS Elusive Unicorn
Message-ID <mailman.11.1464454750.1839.python-list@python.org> (permalink)
References <4743c1df-de66-44e1-9d27-b62582d757ac@googlegroups.com> <eajjkbhks3cj0dpo2ps51pm734b0h1pliq@4ax.com>

Show all headers | View raw


On Sat, 28 May 2016 03:19:10 -0700 (PDT), jobmattcon@gmail.com declaimed
the following:

>for item, i in enumerate(aa)
>  print item
>
>this writing, it can print all values
>
>for item, i in enumerate(aa)
>  if item == findit:
>    print item
>
>this only print the first value, means it only print once then not print again,
>
>where is wrong?

	First thought...

	for i, item in enumerate(aa):

	The first term is the (zero-base) index and the second is the actual
item value.

	No idea what "findit" is, so can't do any further testing, nor what
"aa" contains.

>>> aa = "alcoholics anonymous"
>>> for stuff in enumerate(aa):
... 	print stuff
... 	
(0, 'a')
(1, 'l')
(2, 'c')
(3, 'o')
(4, 'h')
(5, 'o')
(6, 'l')
(7, 'i')
(8, 'c')
(9, 's')
(10, ' ')
(11, 'a')
(12, 'n')
(13, 'o')
(14, 'n')
(15, 'y')
(16, 'm')
(17, 'o')
(18, 'u')
(19, 's')
>>> 

>>> for i, v in enumerate(aa):
... 	if v == "o":
... 		print i
... 
3
5
13
17
>>> 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

why for loop print only once after add if statement jobmattcon@gmail.com - 2016-05-28 03:19 -0700
  Re: why for loop print only once after add if statement Sayth Renshaw <flebber.crue@gmail.com> - 2016-05-28 03:49 -0700
  Re: why for loop print only once after add if statement Peter Otten <__peter__@web.de> - 2016-05-28 13:54 +0200
  Re: why for loop print only once after add if statement Steven D'Aprano <steve@pearwood.info> - 2016-05-28 22:02 +1000
  Re: why for loop print only once after add if statement meInvent bbird <jobmattcon@gmail.com> - 2016-05-28 05:31 -0700
  Re: why for loop print only once after add if statement meInvent bbird <jobmattcon@gmail.com> - 2016-05-28 05:35 -0700
  Re: why for loop print only once after add if statement Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-05-28 12:59 -0400

csiph-web