などの文字列を整数型のリストにします
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
moji = ("2 4 6 8 -10 15 -19 21") | |
mojilist = moji.split(" ") #mojiをスペースで区切ってリストに変換 | |
integer = list(map(int,mojilist)) #リスト内の文字列をint型に変換 | |
print (integer) |
map関数に関していろいろ書こうと思いましたが、私自身まだmapの使い方がよくわからなかったので、今後勉強していきたいと思います
とりあえず今回は魔法の言葉として書いておきます
integer = list(map(int,mojilist))
型変換のとき、listを追加しないとエラーを吐くようなので忘れないようにしましょう
使い方の例を示します
文字列のうち、最大値を出力するときは max(リスト)を使います
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
moji = ("2 4 6 8 -10 15 -19 21") | |
mojilist = moji.split(" ") #mojiをスペースで区切ってリストに変換 | |
integer = list(map(int,mojilist)) #リスト内の文字列をint型に変換 | |
print (max(integer)) |
最小値はmin()にします
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
moji = ("2 4 6 8 -10 15 -19 21") | |
mojilist = moji.split(" ") #mojiをスペースで区切ってリストに変換 | |
integer = list(map(int,mojilist)) #リスト内の文字列をint型に変換 | |
print (min(integer)) |
最近風邪気味で1日だけプログラミング練習できませんでした。
1日だけなのにいろいろと忘れてしまったような感覚に陥ってます。怖いですね。
入門・初心者はやっぱり1日に少しでも練習できると良いですね
0 件のコメント:
コメントを投稿