Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配列全てに処理する色々な方法 #27

Open
higurashi-takuto opened this issue Feb 22, 2019 · 3 comments
Open

配列全てに処理する色々な方法 #27

higurashi-takuto opened this issue Feb 22, 2019 · 3 comments

Comments

@higurashi-takuto
Copy link
Member

Code Author: @kumbikumbiSIC
Knock Number: 04
まだ書きかけだとは思うけど、次の表記について似ている表現が色々思いついたので、参考にしてみてください。

for i in range(0,len(msg2)):
msg2[i] = msg2[i].replace("," , "").replace("." , "")

# 方法1: 配列はイテレータブルなのでforで要素を直接取り出せます。
word = []
for w in msg2:
    word.append(w.replace(",", "").replace(".", ""))

# 方法2: インデックスをつけたい場合はenumerate()が使えます。
for i, w in enumerate(msg2):
    msg2[i] = w.replace(",", "").replace(".", "")

# 方法3: また、配列の全要素に同じ処理をするにはmap()が使えます。(戻り値がmapなのでlistにする必要があります)
msg2 = list(map(lambda word: word.replace(",", "").replace(".", ""), msg2))
@Hikaru-Morita
Copy link
Member

まずイテレータブルを理解してなかったですね

@higurashi-takuto
Copy link
Member Author

ごめん、イテラブル(iterable)だった。

@Hikaru-Morita
Copy link
Member

イテラブルでも分かってなかったですね!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants