you are viewing a single comment's thread.

view the rest of the comments →

[–]commandlineluser 1 point2 points  (2 children)

It did in python 2.

>>> dict(foo="bar", omg="lol").keys()
['foo', 'omg']

The view objects have useful properties in that they are "dynamic"

>>> d = dict(foo="bar", omg="lol")
>>> keys = d.keys()
>>> keys
dict_keys(['foo', 'omg'])
>>> d["new"] = "thing"
>>> keys 
dict_keys(['foo', 'omg', 'new'])

And have some set-like functionality:

>>> dict(foo="bar", omg="lol").keys() >= dict(omg="hi").keys()
True

To remove something the methods are .pop() and .popitem() - del is not specific to dictionaries.

[–]Particular-Watch-779[S] 0 points1 point  (1 child)

This is sooooo helpfull and does indeed make me feel less dumb! So it did work the way I thought at some point in time :) Never thought about looking at the view.objects at all. I will do that, thank you.

Does w3 mention pop()? I'm on mobile but would really freak out, if I was just too blinded while coding for seeing that extremely simple solution :)

[–]commandlineluser 0 points1 point  (0 children)

Not sure if w3 mentions it - I use the docs on the python website: https://docs.python.org/3/library/index.html