count in 'for ... in ...'
DeVerter at robinsonmechanical.com
DeVerter at robinsonmechanical.com
Fri Nov 9 17:42:12 EST 2001
Or try this:
for s in my_list:
print str(my_list.index(s)+1) + ". " + s
Mark d.
Uwe Schmitt
<uwe at rocksport.de> To: python-list at python.org
Sent by: cc:
python-list-admin@ Subject: Re: count in 'for ... in ...'
python.org
11/06/01 08:58 AM
Achim Domma <achim.domma at syynx.de> wrote:
| Hi,
| if I have a list of strings and want to display with a count in front of
it
| I usualy do something like:
| for i in range(len(my_list)):
| print i,". ",my_list[i]
| but I think the
| for s in my_list:
| print ...
What about the following ?
idx=0
for s in my_list:
print idx,".",s
idx+=1
Greetings, Uwe
--
Dr. Uwe Schmitt Uwe.Schmitt at num.uni-sb.de
Universitaet des Saarlandes Angewandte Mathematik
Building 36.1 Room 4.17 PO-Box 151150 D-66041 Saarbruecken
Mobile:0177/6806587 Fax:+49(0)681/302-4435 Office:+49(0)681/302-2468
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list