Changes between Version 24 and Version 25 of DeveloperGuidelines/Py_2_3


Ignore:
Timestamp:
06/28/19 08:24:43 (6 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Py_2_3

    v24 v25  
    128128
    129129The same applies to {{{dict.iterkeys()}}} (use {{{dict.keys()}}} instead) and {{{dict.itervalues()}}} (use {{{dict.values()}}} instead).
     130
     131=== Map and Zip return generators ===
     132
     133In Python-3, the {{{map()}}} and {{{zip()}}} functions return generator objects rather than lists. Where lists are required, the return value must be converted explicitly using the list constructor. Where possible, we prefer list comprehensions.
     134{{{
     135# This is fine:
     136for item in map(func, values):
     137# This could be wrong:
     138result = map(func, values)
     139# This is better:
     140result = list(map(func, values))
     141# This could be even better (though not for multiple iterables):
     142result = [func(v) for v in values]
     143}}}