Skip to content

Commit f062067

Browse files
Merge pull request #70 from cdlab-sit/octan
Octan
2 parents 4b38fbb + 4c414cc commit f062067

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

octan/09.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# スペースで区切られた単語列に対して,各単語の先頭と末尾の文字は残し,それ以外の文字の順序をランダムに並び替えるプログラムを作成せよ.
2+
# ただし,長さが4以下の単語は並び替えないこととする.
3+
# 適当な英語の文(例えば"I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind .")を与え,その実行結果を確認せよ.
4+
import random
5+
6+
string = "I couldn't believe that I could actually understand what I was"\
7+
" reading : the phenomenal power of the human mind ."
8+
lis = string.split()
9+
rnd_list = []
10+
11+
for word in lis:
12+
if 4 < len(word):
13+
word = word[0] + \
14+
"".join(random.sample(word[1:-1], len(word[1:-1]))) + word[-1]
15+
rnd_list.append(word)
16+
17+
rnd_string = " ".join(rnd_list)
18+
print(rnd_string)

octan/10.py

Whitespace-only changes.

0 commit comments

Comments
 (0)