Advertisement
overloop

distribute.py

Dec 13th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1.  
  2. def distribute(es,n):
  3.   """
  4.  >>> distribute([10,11,12],4)
  5.  [[], [10], [11], [12]]
  6.  >>> distribute([10,11,12,13],4)
  7.  [[10], [11], [12], [13]]
  8.  >>> distribute([10,11,12,13,14],4)
  9.  [[10], [11], [12], [13, 14]]
  10.  >>> distribute([10,11,12,13,14,15,16],4)
  11.  [[10], [11, 12], [13, 14], [15, 16]]
  12.  >>> distribute([10,11,12,13,14,15,16,17,18,19],4)
  13.  [[10, 11], [12, 13, 14], [15, 16], [17, 18, 19]]
  14.  """
  15.   p = [ (len(es) * (i+1) / n) - (len(es) * i / n) for i in range(n) ]
  16.   res = []
  17.   e = enumerate(es)
  18.   for m in p:
  19.     res.append([next(e)[1] for i in range(m)])
  20.   return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement