[Tutor] printing a key not a value
Joel Goldstick
joel.goldstick at gmail.com
Tue Oct 25 16:02:24 CEST 2011
On Tue, Oct 25, 2011 at 9:45 AM, ADRIAN KELLY <kellyadrian at hotmail.com>wrote:
> if i have a dictionary called definitions is there a way of printing the
> keys and not the values that go with them?
>
> thanks so much
>
>
>
> Adrian
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> The python.org documentation is a good place to learn about dictionaries.
http://docs.python.org/library/stdtypes.html#mapping-types-dict
As it turns out, you can iterate over the keys of a dictionary:
>>> definitions = {'k1':'k1 value', 'k2': 'k2 value'}
>>> for k in definitions:
... print k
...
k2
k1
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111025/cc9aa841/attachment-0001.html>
More information about the Tutor
mailing list