Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. def my_approach(a):
  2.  
  3. tot_samples = len(a)
  4. choices = set(range(5000)).difference(a)
  5.  
  6. replacements = defaultdict(list)
  7. first_seen = True
  8. current_chain = []
  9.  
  10. for i, val in enumerate(a):
  11. if i == tot_samples - 1:
  12. current_chain.append(i)
  13. if a[-1] == current_chain[-1]:
  14. current_chain.append(i+1)
  15. replacements[val].append(current_chain)
  16. else:
  17. replacements[a[-1]].append([i])
  18. break
  19.  
  20. if first_seen:
  21. current_chain.append(i)
  22. first_seen = False
  23.  
  24. if a[i+1] == val:
  25. current_chain.append(i+1)
  26. else:
  27. replacements[val].append(current_chain)
  28. current_chain = []
  29. first_seen = True
  30.  
  31. for k, v in replacements.items():
  32. if len(v) > 1:
  33. for chunk in range(1, len(v)):
  34. replacement_val = random.choice(list(choices))
  35. choices.add(replacement_val)
  36. for index in v[chunk]:
  37. a[index] = replacement_val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement