[Tutor] for each dictionary key...

Doug Stanfield DOUGS@oceanic.com
Sat, 7 Apr 2001 14:05:34 -1000


Well,

 	for key in self.someclass.keys():
 		( do something )

But shorter doesn't always mean better if it reduces the ability to easily
understand the code.  Thats a judgement call you have to make.  Also, if you
decided later that you needed to sort those keys, you'd probably have to go
back to your original with the addition of...

	keys.sort()

HTH
-Doug-

> -----Original Message-----
> From: Scott [mailto:syrinx@simplecom.net]
> Sent: Saturday, April 07, 2001 1:38 PM
> To: tutor@python.org
> Subject: [Tutor] for each dictionary key...
> 
> 
> 
> I've been doing this:
> 
> 	keys = self.someclass.keys()
> 	for key in keys:
> 		( do something )
> 
> What's the shorter way?
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>