repl.it
@t3m2/

Jumbled sentence

Python

Jumbles a sentence in a certain way: https://www.mrc-cbu.cam.ac.uk/people/matt.davis/cmabridge/

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
This program puts the letters in the middle of the words in a given sentence in a random order. Some say that, by doing this, we are still able to read the sentece: https://www.mrc-cbu.cam.ac.uk/people/matt.davis/cmabridge/

Made by @t3m2 in 2019.
"""                                           
from random import sample

def jumbled_sentence(sentence):
  """
  This function puts the letters in the middle of the words in a given string in a random order, some say that, by doing this, we are still able to read the sentece: https://www.mrc-cbu.cam.ac.uk/people/matt.davis/cmabridge/
  """
  new_sentence=""
  word=""
  for i,char in enumerate(sentence+' '):
    if char.isalpha():
      word+=char
    else:
      if word:
        if len(word)<4:
          new_sentence+=word
        else:
          new_sentence += word[0] + ''.join(sample(word[1:len(word)-1],len(word)-2)) + word[len(word)-1]
        word=""
      new_sentence+=char
  return new_sentence

print("Your jumbled text: %s" % jumbled_sentence(input("Enter a text: ")))

"""

# In this part I was trying different functions to see which was more efficient. (I had never used timeit before and it very interesting :)

frase="As a mod somewhere else I can tell: the admins normally know for sure which accounts belong together. For example, they will know with which accounts I play my serious rated games."

import timeit

for i in range(10):
  print(timeit.timeit('jumbled_sentence1(frase)', globals=globals(),number=1000), end='; ')
  print(timeit.timeit('jumbled_sentence2(frase)', globals=globals(),number=1000), end='; ')
  print(timeit.timeit('jumbled_sentence3(frase)', globals=globals(),number=1000), end='; ')
  print()


"""
Fetching token
?