Wednesday, January 12, 2011

Generator expression

I hope I'm doing this right...
Project Euler Problem 99
import math, operator, csv

f = csv.reader(open('base_exp.txt'), delimiter=',')
lines = (map(int, line) for line in f)

print max(
    enumerate(
      (math.log(b) * e for b, e in lines),
      1
    ),
    key=operator.itemgetter(1)
)

No comments:

Post a Comment