0
1

More than 3 years have passed since last update.

RubyとPythonとmap

Last updated at Posted at 2019-11-26

一方の言語でのイメージが邪魔して、もう一方の言語での書き方が思い出せない時がたまにあるんです。

Python
map(lambda n: str(n).rjust(3,"0"), [1,2,3])
>> ["001", "002", "003"]
Ruby
[1,2,3].map{|n| n.to_s.rjust(3,"0")}
>> ["001", "002", "003"]
0
1
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1