How can i retrieve a key from a dictionary?

Husam h.jehadalwan at student.kun.nl
Sun Nov 4 07:53:16 EST 2001


Nils Kassube wrote:

> Husam <h.jehadalwan at student.kun.nl> writes:
>
> > dict.keys() will gets all the keys. but, i need to select explicitly one
> > key for printing along its value.
>
> >>> dict={}
> >>> dict[1]="Foo"
> >>> print dict[1]
> Foo
>
> This dictionary method is also useful:
>
> >>> print {}.get.__doc__
> D.get(k[,d]) -> D[k] if D.has_key(k), else d.  d defaults to None.
>
> i.e. to have a default value of 42 for the key 2 which is used
> when an entry for 2 is missing:
>
> >>> print dict.get(2, 42)
> 42
>
> Please read the tutorial before asking any other question.
> Danke.

wrong answer! this is not what i ment.




More information about the Python-list mailing list