Feb-23-2019, 11:07 PM
Hi DionisiO,
There are a number of ways to write shorter versions of what your code does (at least without the [printing), for example...
In four lines:
There are a number of ways to write shorter versions of what your code does (at least without the [printing), for example...
In four lines:
puntos.loc[puntos.localGoals > puntos.visitorGoals, 'PuntosLocal'] = 3 puntos.loc[puntos.localGoals < puntos.visitorGoals, 'PuntosLocal'] = 0 puntos.loc[puntos.localGoals == puntos.visitorGoals, 'PuntosLocal'] = 1 puntos['PuntosVisitante'] = puntos.PuntosLocal.map(lambda pl: {3: 0, 0: 3, 1: 1}[pl])or in "one" line:
puntos['PuntosLocal'], puntos['PuntosVisitante'] = zip(*[ (3, 0) if local > visitor else (0, 3) if local < visitor else (1, 1) for local, visitor in zip(puntos.localGoals, puntos.visitorGoals) ])On the other hand, I read your code and knew exactly what it did within a couple seconds. Can you honestly do that for either of my options? Your code is reasonably efficient, and very readable - not too bad!