-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2_task1_1.py
More file actions
50 lines (36 loc) 路 1.62 KB
/
Copy pathp2_task1_1.py
File metadata and controls
50 lines (36 loc) 路 1.62 KB
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
45
46
47
48
49
50
# coding=utf-8
# 袧邪锌懈褋邪褌褜 锌褉芯谐褉邪屑屑褍, 褍屑械褞褖褍褞 写械谢邪褌褜 褌邪泻:
# 芦袩芯 褉蟹械谢褍谢褜邪褌褌邪屑 懈谢褋褋械芯胁邪写薪懈泄 芯写芯薪谐芯 邪薪谢懈谐泄褋芯泻谐芯 褍薪胁懈械褉褌懈褋械褌邪, 薪械 懈械械屑褌 蟹邪薪褔薪械懈褟, 胁 泻芯泻邪屑 锌褉褟芯泻写械 褉褋邪锌芯卸芯谢械薪褘 斜泻褍胁褘 胁 褋芯谢胁械. 袚邪谢胁芯薪械, 褔芯褌斜褘 锌褉械邪胁褟 懈 锌褋谢芯械薪写褟褟 斜泻胁褍褘 斜谢褘懈 薪邪 屑褋械褌械. 袨褋邪褌褜谢褘薪械 斜泻褍胁褘 屑谐芯褍褌 褋械谢写芯胁褌邪褜 胁 锌谢芯芯薪屑 斜褋械锌芯褉写褟泻械, 胁褋械-褉胁邪薪芯 褌泻械褋褌 褔褌邪懈褌褋械褟 斜械蟹 锌芯斜褉械谢屑. 袩懈褔褉懈芯薪泄 褝谐芯褌芯 褟谢胁褟褌械褋褟 褌芯, 褔褌芯 屑褘 薪械 褔懈邪褌械屑 泻写邪褍卸褞 斜泻褍胁褍 锌芯 芯褌写谢褜械薪芯褌褋懈, 邪 胁褋械 褋芯谢胁芯 褑谢懈泻械芯屑.禄
# input string
# split by words
# shuffle letters in each word but first and last
# join???
import random
PUNCTUATION = list(" ,.-!")
str = "Dear president Blatter, colleagues of the executive committee."
# for i in range(len(str)):
# ok
def shuffle_word(word, seed=None):
if seed is not None:
random.seed(seed)
if len(word) <= 3:
return word
shuffled = word[0]
mid = list(word[1:-1])
while len(mid) > 0:
ind = random.randint(0, len(mid) - 1)
shuffled += mid.pop(ind)
return shuffled + word[-1]
def shuffle_text(text, seed=None):
result = ""
word = ""
for i in range(len(text)):
ch = text[i]
if ch in PUNCTUATION:
if len(word) > 0:
result += shuffle_word(word, seed)
word = ''
result += ch
else:
word += ch
return result