On Wed, Apr 23, 2008 at 10:35 PM, Alex Martelli <<a href="mailto:aleaxit@gmail.com">aleaxit@gmail.com</a>> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is 119 vs 117 characters "a LOT of verbosity"...?! OK, then what about...:</blockquote><div><br>the reduce is actually 69 *and only one line* if you don't need it in a function. You can't put the dhms2 in a function unless you want to leak a bunch of variables like 'd', 'r', and 't'...<br>
reduce(lambda a, b: a[:-1] + [a[-1]%b, a[-1]//b], [[t], 60, 60, 24])<br></div></div><br>On Wed, Apr 23, 2008 at 10:40 PM, "Martin v. Löwis" <<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">py> time % 60, time//60%60, time//3600%24, time//(3600*24)<br>
(28, 7, 0, 22)</blockquote><div>the 3600 and 3600*24 was what I was trying to avoid. I like the divmod solution. You can also use it in the reduce :)<br>reduce(lambda a, b: divmod(a[0], b) + a[1:], [(t,), 60, 60, 24])[::-1]<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
P.S. I'm not sure why you had been using floating point<br>
operations.</blockquote></div>no, this wasn't necessary, I didn't know about "//". I could have used int as well...<br><br>Nicholas