Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

Dictionary iterates over keys and this is expected behavior. If you need to 
iterate by values you should use dict().values()

$ python3 -c 'for i in dict(a=1): print(i)'
a
$ python3 -c 'print(all(dict(a=False)))' # Iterate by keys and thus 'a' is True
True
$ python3 -c 'print(all(dict(a=False).values()))' # Iterate by values explicitly
False

# Relevant PEP section :

https://www.python.org/dev/peps/pep-0234/#dictionary-iterators

> Dictionaries implement a tp_iter slot that returns an efficient iterator that 
> iterates over the keys of the dictionary. During such an iteration, the 
> dictionary should not be modified, except that setting the value for an 
> existing key is allowed (deletions or additions are not, nor is the update() 
> method). This means that we can write

> for k in dict: ...

https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops


This is not a bug but an expected behavior unless I am missing something from 
the script attached

----------
nosy: +xtreak

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35175>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to