import random


def random_word_delete(sentence, p):
  """Deletes a word from a sentence with probability p."""

  words = sentence.split(' ')

  # Return if one word.
  if len(words) == 1:
    return words[0]

  # Randomly delete words.
  new_words = []
  for word in words:
    if random.uniform(0, 1) > p:
      new_words.append(word)

  # If all words are removed return one.
  if not new_words:
    rand_int = random.randint(0, len(words) - 1)
    return words[rand_int]

  sentence = ' '.join(new_words)

  return sentence