Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countocurrences(numbers, minlength=0):
- """Takes a list of integers numbers, in the range of 0..n and returns
- a list of integers where i-th item is the number of times i appears in types.
- If minlength is specified and n+1 < minlength, the returned list is right-padded
- with zeroes to make it contain minlength items.
- Examples:
- >>> counttypes([0,3,1,2,1,1,3,5])
- [1,3,1,2,0,1]
- >>> counttypes([0,3,1,2,1,1,3,5], 10)
- [1,3,1,2,0,1,0,0,0,0]
- """
- # TODO come up with a better name
- counts = [0] * max(max(numbers)+1, minlength)
- for x in numbers:
- counts[x] += 1
- return counts
Add Comment
Please, Sign In to add comment