Domanda

The documentation for Python map() states in part:

If function is None, the identity function is assumed;

Therefore, if I have some Python code like this:

def yearsback(tbl, yb):
    def fcn():
      y = None
      i = 0
      for (year, prefix, suffix) in reversed(sorted(tbl.iterkeys())):
        if y == None:
          y = year
        elif y > year:
          i, y = 1 + i, year
        if i >= yb:
          return
        yield (year, prefix, suffix)
    return map(None, fcn())

Is there a simpler way to write that? Also, I suspect the reversed(sorted(tbl.iterkeys())) could also be simplified.

È stato utile?

Soluzione

All you would need to do is -

list(fcn())

If you want an iterator, use -

iter(fcn())
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top