| python Programming Glossary: divmodPython: Date manipulation code http://stackoverflow.com/questions/11157164/python-date-manipulation-code  without the calendar module def last_day dt rest month divmod dt.month 12 return date dt.year rest month 1 1 timedelta days.. rest month 1 1 timedelta days 1 This function uses the divmod builtin function to handle the 'current month is December' edge.. back to the 'start' is the modulus of the number but the divmod function gives us the divisor as well which happens to be 1.. 
 Python base 36 encoding http://stackoverflow.com/questions/1181919/python-base-36-encoding  return sign alphabet number while number 0 number i divmod number len alphabet base36 alphabet i base36 return sign base36.. 
 How do I find the time difference between two datetime objects in python? http://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python  datetime.datetime.now c b a datetime.timedelta 0 8 562000 divmod c.days 86400 c.seconds 60 0 8 # 0 minutes 8 seconds   share.. 
 Python modulo on floats http://stackoverflow.com/questions/14763722/python-modulo-on-floats  you may be able to rely on this. And if not you can use divmod 3.5 0.1 which returns within rounding error 34.0 0.09999999999999981.. 
 how to print number with commas as thousands separators in Python 2.x http://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators-in-python-2-x  x 0 return ' ' intWithCommas x result '' while x 1000 x r divmod x 1000 result 03d s r result return d s x result Recursion is.. 
 Python elegant inverse function of int(string,base) http://stackoverflow.com/questions/2063425/python-elegant-inverse-function-of-intstring-base  base if number 0 return ' ' str_base number base else d m divmod number base if d return str_base d base digit_to_char m else.. 
 How to Convert DD to DMS in Python http://stackoverflow.com/questions/2579535/how-to-convert-dd-to-dms-in-python    share improve this question   This is exactly what divmod was invented for def decdeg2dms dd ... mnt sec divmod dd 3600.. what divmod was invented for def decdeg2dms dd ... mnt sec divmod dd 3600 60 ... deg mnt divmod mnt 60 ... return deg mnt sec.. decdeg2dms dd ... mnt sec divmod dd 3600 60 ... deg mnt divmod mnt 60 ... return deg mnt sec dd 45 30.0 60 1.0 3600 print dd.. 
 Python - Homework - Converting Any Base to Any Base http://stackoverflow.com/questions/3973685/python-homework-converting-any-base-to-any-base  def int2str integer base array while integer integer value divmod integer base array.append VA2SY value return ''.join reversed.. them in the right order. array while integer integer value divmod integer convertvar array.append VA2SY value answer ''.join reversed.. 
 what's the 5 character alphanumeric id in reddit URL? http://stackoverflow.com/questions/410485/whats-the-5-character-alphanumeric-id-in-reddit-url  a positive integer l len alphabet converted while q 0 q r divmod q l converted.insert 0 alphabet r return .join converted or.. 
 Python format timedelta to string http://stackoverflow.com/questions/538666/python-format-timedelta-to-string  3 43 40 However python provides the builtin function divmod which allows us to simplify this code s 13420 hours remainder.. allows us to simplify this code s 13420 hours remainder divmod s 3600 minutes seconds divmod remainder 60 print ' s s s' hours.. code s 13420 hours remainder divmod s 3600 minutes seconds divmod remainder 60 print ' s s s' hours minutes seconds # result 3.. 
 How to convert an integer to the shortest url-safe string in Python? http://stackoverflow.com/questions/561486/how-to-convert-an-integer-to-the-shortest-url-safe-string-in-python  if n 0 return SIGN_CHARACTER num_encode n s while True n r divmod n BASE s.append ALPHABET r if n 0 break return ''.join reversed.. 
 Is it pythonic for a function to return multiple values? http://stackoverflow.com/questions/61605/is-it-pythonic-for-a-function-to-return-multiple-values  first class citizens in Python There is a builtin function divmod that does exactly that. q r divmod x y # x x y y x y Invariant.. is a builtin function divmod that does exactly that. q r divmod x y # x x y y x y Invariant div y mod x There are other examples.. 
 Using itertools.product and want to seed a value http://stackoverflow.com/questions/9864809/using-itertools-product-and-want-to-seed-a-value  self.state n x self.num_gears while n 0 and x 0 x 1 n m divmod n len self.gears x  self.indicies x m self.indicies x 1 if n.. count imap def make_product values def fold n l v n m divmod n len v return n l v m def product n n l reduce fold values.. 
 |