Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. def enc_consume(carrier, nsyms):
  2. chrs = defaultdict(int)
  3.  
  4. i = 0 # see this?
  5.  
  6. for i,c in enumerate(carrier):
  7. # `i` is not used in the loop
  8. chrs[c] += 1
  9. if len(chrs) == nsyms:
  10. break
  11.  
  12. return chrs, carrier[i+1:] # but it's used here
  13.  
  14. def enc_consume(carrier, nsyms):
  15. characters = defaultdict(int)
  16. stream = iter(carrier)
  17.  
  18. for char in stream:
  19. characters[char] += 1
  20. if len(characters) >= nsyms:
  21. break
  22.  
  23. return characters, ''.join(stream)
  24.  
  25. def enc_consume(carrier, nsyms):
  26. first_unused_idx = 0
  27. char_cnt = defaultdict(int)
  28. while first_unused_idx < len(carrier) and len(char_cnt) < nsyms:
  29. char_cnt[carrier[first_unused_idx]] += 1
  30. first_unused_idx += 1
  31. return char_cnt, carrier[first_unused_idx:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement