[PATCH 09/15] Replace dictionary iteration methods
Łukasz Żarnowiecki
dolohow at outlook.com
Fri May 13 07:58:11 BST 2016
> Why is this required?
Here is a good explanation[1]. We can safely remove wrapping with list
call when looping if you want to.
> > @@ -1009,14 +1009,14 @@ class BaseFolder(object):
> > delflaglist[flag] = []
> > delflaglist[flag].append(uid)
> >
> > - for flag, uids in addflaglist.items():
> > + for flag, uids in list(addflaglist.items()):
>
> Hmm, does this work as expected?
Yes, output is almost the same. Underling hashing algorithm was
probably changed and the data is differently ordered in memory.
Python2
-------
>>> addflaglist = a
>>> for flag, uids in list(addflaglist.items()):
... print(flag)
... print(uids)
...
a
1
c
3
b
2
>>> for flag, uids in addflaglist.items():
... print(flag)
... print(uids)
...
a
1
c
3
b
2
Python3
-------
addflaglist = {'a': 1, 'b': 2, 'c': 3}
>>> for flag, uids in addflaglist.items():
... print(flag)
... print(uids)
...
c
3
b
2
a
1
>>> for flag, uids in list(addflaglist.items()):
... print(flag)
... print(uids)
...
c
3
b
2
a
1
[1] http://stackoverflow.com/questions/17695456/why-python-3-needs-wrap-dict-items-with-list
More information about the OfflineIMAP-project
mailing list