Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] Syntax for key-value iteration over mappings

Stephen J. Turnbullstephen at xemacs.org
Tue Jul 28 11:46:17 CEST 2015


Nick Coghlan writes: > Looking up the original iterator PEP shows it was done to enforce the > container invariant "for x in y: assert x in y".I would argue that in the context of a given mapping, <key> and[<key>, <value>] are equivalent when <value> is <map>[<key>], so thatwe shou ld have the signature __contains__(self, key, value=self[key]),which is a NameError, but the intent should be obvious.The evident suggestion that we distinguish between tuples (which canbe used as keys) and items by implementing the latter as lists (whichcan't, at least in the case of dictionaries) seems fragile and icky,though, and unacceptable at this point since it's incompatible withthe .items() iterator.


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp