count in 'for ... in ...'

Uwe Schmitt uwe at rocksport.de
Tue Nov 6 10:58:59 EST 2001


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



More information about the Python-list mailing list