Skip to content

Instantly share code, notes, and snippets.

@kai5263499
Created October 1, 2017 21:41
Show Gist options
  • Save kai5263499/a582b173cdd7da2759d1c9d6bd24aa15 to your computer and use it in GitHub Desktop.
Save kai5263499/a582b173cdd7da2759d1c9d6bd24aa15 to your computer and use it in GitHub Desktop.
Mix lists with a given ratio
# inspired by https://stackoverflow.com/questions/10644925/randomly-interleave-2-arrays-in-python
def mix_with_ratio(a, b, ratio):
c = []
while a and b:
which_list = random.random()
if which_list < ratio:
c.append(a.pop(0))
else:
c.append(b.pop(0))
return c
# 10% chance of mixing b into a
mix_with_ratio(['a' for x in range(10)], ['b' for x in range(10)], 0.90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment