Monday, November 6, 2017

Re: When I using dictionary, how can I add items using my input order?

Hi,

You can't, dictionaries are just hash tables, there is no ordering you can count upon.

You'll have either to record a list of the keys in the order you desire, or give up on the big dictionary and use a list instead -- either a list of lists, or a list of dictionaries.


If you don't need the dictionary for anything else, no need to extract all the information.

You should be able to achieve your result the following (which would be more efficient BTW, but I doubt you'd perceive any difference on real code)

let lines = filter(getline(1, '$'), 'v:val !~ "^\\s*$"')
call map(lines, 'substitute(v:val, "^\\s*", "", "")')
let names = map(copy(lines), "substitute(v:val, '\\s*[;,].*$', '', '')")
let newlines = map(copy(names), '"reg ila_".v:val.";"')
call setline(curr_line, newlines)

HTH,

--
Luc Hermitte

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment