Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. def countocurrences(numbers, minlength=0):
  2. """Takes a list of integers numbers, in the range of 0..n and returns
  3. a list of integers where i-th item is the number of times i appears in types.
  4.  
  5. If minlength is specified and n+1 < minlength, the returned list is right-padded
  6. with zeroes to make it contain minlength items.
  7.  
  8. Examples:
  9. >>> counttypes([0,3,1,2,1,1,3,5])
  10. [1,3,1,2,0,1]
  11. >>> counttypes([0,3,1,2,1,1,3,5], 10)
  12. [1,3,1,2,0,1,0,0,0,0]
  13. """
  14. # TODO come up with a better name
  15. counts = [0] * max(max(numbers)+1, minlength)
  16. for x in numbers:
  17. counts[x] += 1
  18. return counts
Add Comment
Please, Sign In to add comment