[Tutor] viewkeys,viewvalues,viewitems : Use Cases

Alan Gauld alan.gauld at btinternet.com
Wed Feb 26 14:29:04 CET 2014


On 26/02/14 07:04, Santosh Kumar wrote:

> I defined a dictionary a below.
>
> In [14]: a = {'a':1,'b':2,'c':3}
>...
> Funtion associated with dictionaries.
>
> In [11]: print a.viewkeys()
> dict_keys(['a', 'c', 'b'])
>
> In [12]: print a.viewvalues()
> dict_values([1, 3, 2])
>
> In [13]: print a.viewitems()
> dict_items([('a', 1), ('c', 3), ('b', 2)])
>
> Where do i use these , can i get any user cases.

What is 'these'?
Do you mean:

1) where do I use a dictionary?
2) where do I use viewXXX()?
3) How do viewXXX differ from XXX (eg a.viewkeys v a.keys)?

I'm not sure which aspect you want help with?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list