ディクショナリ型
作者: 小見 拓
—
最終変更
2012年01月08日 12時14分
ディクショナリ型
- ディクショナリの作成。
:let var_dict_1 = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :echo var_dict_1 "# => {'four': 'item 4', 'one': 'item 1', 'two': 'item 2', 'three': 'item 3'} :let var_dict_2 = {} :echo var_dict_2 "# => {}
- ディクショナリに追加。
:let var_dict = { "one":"item 1", "two":"item 2" } :let var_dict["three"] = "item 3" :echo var_dict "# => {'one': 'item 1', 'two': 'item 2', 'three': 'item 3'} :let var_dict.four = "item 4" :echo var_dict "# => {'four': 'item 4', 'one': 'item 1', 'two': 'item 2', 'three': 'item 3'}
- ディクショナリから削除。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :call remove(var_dict, 'one') :echo var_dict "# => {'four': 'item 4', 'two': 'item 2', 'three': 'item 3'} :unlet var_dict["three"] :echo var_dict "# => {'four': 'item 4', 'two': 'item 2'} :unlet var_dict.two :echo var_dict "# => {'four': 'item 4'}
- ディクショナリに格納されたアイテムの取得。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :echo var_dict["two"] "# => item 2 :echo var_dict.two "# => item 2
- ディクショナリのアイテム数の取得。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :echo len(var_dict) "# => 4
- ディクショナリのキーのリスト。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :echo keys(var_dict) "# => ['four', 'one', 'two', 'three']
- ディクショナリの値のリスト。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :echo values(var_dict) "# => ['item 4', 'item 1', 'item 2', 'item 3']
- ループ。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } :for k in keys(var_dict) :echo k . ":" . var_dict[k] :endfor "# => four:item 4 "# => one:item 1 "# => two:item 2 "# => three:item 3
- フィルタ。
:let var_dict = { "one":"item 1", "two":"item 2", "three":"item 3", "four":"item 4" } " リストから条件にマッチしないアイテムを取り除く " アイテムのキーはv:key、値はv:valに入る :call filter(var_dict, "v:key =~ '^t'") :echo var_dict "# => {'two': 'item 2', 'three': 'item 3'}
Recent Comments
ありがとうございます!
http://nanasi.jp/articles/howto/editing/visualcursor-endtoend.html · 8 years ago
知りませんでした。有難うございました。
http://nanasi.jp/articles/howto/file/open-with-format.html · 9 years ago
<c-f>1ページ分、下にスクロールする<c-b>1ページ分、上にスクロールする
どっちも逆です。
http://nanasi.jp/articles/howto/user-manual/user-manual-motion.html · 10 years ago
set 使用時に : で閉じるのを忘れて右往左往してました。
http://nanasi.jp/articles/howto/file/modeline.html · 11 years ago
やっぱり日本語の方が早いっす。
http://nanasi.jp/articles/howto/help/help_ja.html · 12 years ago