for key : value in dict loop ?

0 views
Skip to first unread message

Marc Weber

unread,
Dec 13, 2008, 10:15:13 AM12/13/08
to vim...@googlegroups.com
Does vimscript prodive something like this?
Right now I keep writing this instead:

let loaded = config#GetG('tovl#plugins#loaded')
for pkey in loaded
let value = loaded[key]
" ....
endfor

which is much more verbose than something like PHP can do

for pkey : value in config#GetG('tovl#plugins#loaded')
....
endfor

(PHP is using => isntead of :. But : feel more natural because you
construct dicts this way)

Marc

Christian Ebert

unread,
Dec 13, 2008, 10:34:58 AM12/13/08
to vim...@googlegroups.com
* Marc Weber on Saturday, December 13, 2008 at 16:15:13 +0100

> Does vimscript prodive something like this?
> Right now I keep writing this instead:
>
> let loaded = config#GetG('tovl#plugins#loaded')
> for pkey in loaded
> let value = loaded[key]
> " ....
> endfor
>
> which is much more verbose than something like PHP can do
>
> for pkey : value in config#GetG('tovl#plugins#loaded')
> ....
> endfor

According to :help Dictionaries

for pkey in keys(config#GetG('tovl#plugins#loaded')
...
endfor

:help keys()

c
--
\black\trash movie _C O W B O Y_ _C A N O E_ _C O M A_
Ein deutscher Western/A German Western
-->> http://www.blacktrash.org/underdogma/ccc.html
-->> http://www.blacktrash.org/underdogma/ccc-en.html

Marc Weber

unread,
Dec 13, 2008, 10:45:14 AM12/13/08
to vim...@googlegroups.com
> for pkey in keys(config#GetG('tovl#plugins#loaded')
> ...
> endfor
>
> :help keys()

Sorry, typo. Of course I know about keys(). But I still have to get the
value myself then..

Marc

Tom Link

unread,
Dec 13, 2008, 12:30:57 PM12/13/08
to vim_use
> Sorry, typo. Of course I know about keys(). But I still have to get the
> value myself then..

for [key, value] in items(var)
...
unlet key value
endfor
Reply all
Reply to author
Forward
0 new messages