Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_approach(a):
- tot_samples = len(a)
- choices = set(range(5000)).difference(a)
- replacements = defaultdict(list)
- first_seen = True
- current_chain = []
- for i, val in enumerate(a):
- if i == tot_samples - 1:
- current_chain.append(i)
- if a[-1] == current_chain[-1]:
- current_chain.append(i+1)
- replacements[val].append(current_chain)
- else:
- replacements[a[-1]].append([i])
- break
- if first_seen:
- current_chain.append(i)
- first_seen = False
- if a[i+1] == val:
- current_chain.append(i+1)
- else:
- replacements[val].append(current_chain)
- current_chain = []
- first_seen = True
- for k, v in replacements.items():
- if len(v) > 1:
- for chunk in range(1, len(v)):
- replacement_val = random.choice(list(choices))
- choices.add(replacement_val)
- for index in v[chunk]:
- a[index] = replacement_val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement