Loading ...
Sorry, an error occurred while loading the content.

118029Re: Adding items'List to items'List2

Expand Messages
  • Benjamin R. Haskell
    Oct 6, 2010
      On Wed, 6 Oct 2010, epanda wrote:

      > Hi,
      >
      > I have two Lists:
      > let list1=['','','','barfoo']
      > let list2=['foo','bar','foobar']
      >
      > I would like to obtain this List :
      > listResult = ['foo','bar','foobar','barfoo']
      >
      > ..without looping manually by for or while around my List.

      It's unclear from the description why the result is the way it is.
      Does it need to start at the first non-empty item of list1? Or does it
      only need to know the length of list2?

      If the former: (append non-empty elements of list1 to list2)

      let listResult = extend(copy(list2), filter(list1, 'strlen(v:val)'))

      :help extend()
      :help copy() " only if you need to use list2 again later
      :help filter()
      :help strlen() " only needed if '0' is a valid item


      If the latter: (just append anything beyond the end of list2 from list1)

      if len(list1) > len(list2)
      let listResult = extend(copy(list2), list1[len(list2):])
      endif

      :help list-index, then search for 'Sublist'

      --
      Best,
      Ben

      --
      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
    • Show all 5 messages in this topic