count objects in a list and random numb gen

Robert Brewer fumanchu at amor.org
Thu Jan 8 18:29:50 EST 2004


Bart Nessux wrote:
> New to Python... trying to figure out how to count the 
> objects in a list 
> and then map the count to the objects or convert the list to 
> a dict... I 
> think the latter would be better as I need a number 
> associated with each 
> entry. Any pointers?

You want enumerate().

>>> for index, val in enumerate(['a', 'b', 'c']):
... 	print index, val
... 	
0 a
1 b
2 c


FuManChu




More information about the Python-list mailing list