今という器の中から

過ごした時間を振り返る雑記ブログ

python

pythonを使った、英文を分解し,アルファベットの文字数を取得したリストの作成の学習メモ

sentence = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics." count = [len(word.strip(".,")) for word in sentence.split()] print(count) 言語処理100本ノック 第1章 in Python - Qiita sentence="Now…

pythonを使った、文字列の相互連結

s1 = "パトカー" s2 = "タクシー" print(''.join([char1 + char2 for char1, char2 in zip(s1, s2)])).join とは join: 文字列シーケンスの連結 sep.join(seq) sepを区切り文字として、seqを連結してひとつの文字列にする。 今回は区切り文字を用いず、[char…

pythonを使った、リストの逆順ではなく文字列の反転

大体のプログラミング言語では reverse メソッドが使われるらしい。しかし、python には reverse メソッドに当たるものがないらしい。reverse メソッドがない代わりにpython ではスライスを用いる。 スライスとは オブジェクトの中の指定した範囲の要素を持…