Help us understand the problem. What is going on with this article?

平仮名・片仮名の小文字を大文字にするワンライナー

概要

translate_large_kana = lambda x: x.translate(dict([(ord(k), ord(k) + 1) for k in ('ぁ', 'ァ', 'ぃ', 'ィ', 'ぅ', 'ゥ', 'ぇ', 'ェ', 'ぉ', 'ォ', 'っ', 'ッ', 'ゃ', 'ャ', 'ゅ', 'ュ', 'ょ', 'ョ')]))
translate_large_kana('シャツ')
# シヤツ

何コレ?

  • ord('ぁ')ord('あ') みたいな小文字と大文字は ord の差が 1 なので、 chr(ord('ぁ') + 1) == 'あ'になる
  • ↑の概念をもとに、小文字を大文字に変換する辞書を作成して、 str.translate する
  • という lambda 関数を作った
debari
博士(情報科学)。 ZETA株式会社のエンジニア。検索エンジンを作ったり、レコメンドエンジンを作ったり。
zeta
サイト内検索/レコメンドを主軸としたECソリューションを開発・提供。ディープラーニング技術のEC展開にも注力しています。
https://zeta.jpn.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした