Duh v D'oh

Paul Makepeace paulm at paulm.com
Fri Nov 7 12:11:37 GMT 2008


On Fri, Nov 7, 2008 at 11:48 AM, Peter Corlett <abuse at cabal.org.uk> wrote:

> On Thu, Nov 06, 2008 at 05:00:16PM +0000, Nigel Rantor wrote:
> > Paul Makepeace wrote:
> [...]
> >> If it's not staring out at you, you're possibly also a python
> programmer.
> >> Python here arguably DWIM better than perl.
> > Does python give you the keys by default?
>
> Sort of. In Python, "for" loops over values returned by an iterator, and a
> hash implements that interface.


The interface is pretty clean,

my_dict = {'a': 1, 'b': 2}
for k in my_dict:
  print k

gives,
a
b

for k, v in my_dict.items():
  print k, v

gives,
a 1
b 2

(ObPedantry, .iteritems() is preferred since it evaluates lazily with a
generator.)

P


More information about the london.pm mailing list