-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from cdlab-sit/higurashi-takuto
Higurashi takuto
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# 「パタトクカシーー」という文字列の1,3,5,7文字目を取り出して連結した文字列を得よ. | ||
|
||
string = 'パタトクカシーー' | ||
|
||
# スライス[開始:終了:ステップ] | ||
string_step = string[::2] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics."という文を単語に分解し,各単語の(アルファベットの)文字数を先頭から出現順に並べたリストを作成せよ. | ||
|
||
import re | ||
|
||
string = 'Now I need a drink, alcoholic of course, '\ | ||
'after the heavy lectures involving quantum mechanics.' | ||
|
||
# 正規表現で,.を消してスペースで分割、その後文字列の長さを見る。 | ||
string = re.sub(r'[^\w\s]', '', string) | ||
num_char = list(map(len, string.split(' '))) | ||
|
||
print(num_char) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."という文を単語に分解し,1, 5, 6, 7, 8, 9, 15, 16, 19番目の単語は先頭の1文字,それ以外の単語は先頭に2文字を取り出し,取り出した文字列から単語の位置(先頭から何番目の単語か)への連想配列(辞書型もしくはマップ型)を作成せよ. | ||
|
||
import re | ||
|
||
string = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. '\ | ||
'New Nations Might Also Sign Peace Security Clause. Arthur King Can.' | ||
|
||
# 正規表現で,.を消してスペースで分割。 | ||
string = re.sub(r'[^\w\s]', '', string) | ||
word = string.split(' ') | ||
|
||
# 本当はscope = [0, 4, 5, 6, 7, 8, 14, 15, 18]の一行で18行目までは省略できる。 | ||
scope_range = [0, range(4, 9), range(14, 16), 18] | ||
scope = [] | ||
for i in scope_range: | ||
if isinstance(i, int): | ||
scope.append(i) | ||
else: | ||
scope.extend(i) | ||
|
||
# 辞書内包表記のif elseはkey, valueそれぞれに必要。 | ||
element2num = {_word[:1] if i in scope else _word[:2]: i + 1 | ||
for i, _word in enumerate(word)} | ||
|
||
print(element2num) |