Hash from two arrays: Difference between revisions

→‎{{header|Python}}: Current versions up-front. 2.7 has dict comprehensions too.
(→‎{{header|Python}}: Current versions up-front. 2.7 has dict comprehensions too.)
Line 916:
 
=={{header|Python}}==
{{works with|Python|3.0+ and 2.7}}
Shows off the dict comprehensions in Python 3 (that were back-ported to 2.7):
<lang python>keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = {key: value for key, value in zip(keys, values)}</lang>
 
{{works with|Python|2.2+}}
<lang python>keys = ['a', 'b', 'c']
Line 924 ⟶ 930:
from itertools import izip
hash = dict(izip(keys, values))</lang>
 
{{works with|Python|3.0+}}
Shows off the dict comprehensions in Python 3:
<lang python>keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = {key: value for key, value in zip(keys, values)}</lang>
 
{{works with|Python|2.0+}}
Anonymous user