Maurice <mauricioliveiragua...@gmail.com> writes: > Hello, hope everything is okay. I think someone might have dealt with > a similar issue I'm having. > > Basically I wanna do the following: > > I have a list such [6,19,19,21,21,21] (FYI this is the item of a >certain key in the dictionary) > > And I need to convert it to a list of 32 elements (meaning days of the > month however first element ie index 0 or day zero has no meaning - > keeping like that for simplicity's sake).
> Therefore the resulting list should be: > [0,0,0,0,0,0,1,0,0,0...,2,0,3,0...0] How about reduce(lambda counts, day: counts[:day] + [counts[day]+1] + counts[day+1:], days, [0]*32) ? (reduce is in functools). Not efficient, but sometimes you just want to the job done. More efficient would be: def inc_day(counts, day): counts[day] += 1; return counts reduce(inc_day, days, [0]*32) For experts here: why can't I write a lambda that has a statement in it (actually I wanted two: lambda l, i: l[i] += 1; return l)? <snip> -- Ben. -- https://mail.python.org/mailman/listinfo/python-list