Talk:Associative array/Iteration: Difference between revisions

Content added Content deleted
No edit summary
(This is the problem)
Line 2: Line 2:


:Hi Dmitry, iterating over all the members of an associative array is quite a common practice in Python. The keys/values may not appear in any particular order, but you must be guaranteed to go over each and every key/value only once. Python has the added assurance that if the associative array is unchanged, iterating over all keys , then iterating over all values will give the values in corresponding order to their keys; but that is not called for in this task. --[[User:Paddy3118|Paddy3118]] 09:32, 3 August 2009 (UTC)
:Hi Dmitry, iterating over all the members of an associative array is quite a common practice in Python. The keys/values may not appear in any particular order, but you must be guaranteed to go over each and every key/value only once. Python has the added assurance that if the associative array is unchanged, iterating over all keys , then iterating over all values will give the values in corresponding order to their keys; but that is not called for in this task. --[[User:Paddy3118|Paddy3118]] 09:32, 3 August 2009 (UTC)

::Hi! Yes this is IMO the problem with this task. An associative array is not required to provide a conversion to an ordered set of pairs (key, value), which technically is what you described. Yes, it can, but so can any container on any finite machine. You can always order any finite set. The question whether any unordered map shall provide such conversion (in place (a view) or physical (a copy)) is another issue. There can be arguments for and against it. But it is not a programming task, it is a question of a container library design. Phyton's library took one choice, other libraries could do another. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 10:05, 3 August 2009 (UTC)