LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Stuck on lists

    Employee
    Posted 10-10-2013 11:37

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dstacey

    Please help me this must be really simple - I want to add items to a list and set items in a list. I thought append and setItem would solve all my problems. I tried this simple filter:

    x = list(1,2,3)
    setItem(x, 2, 6)
    x.append(10)

    y = x[2]
    z = x[3]
    emit y, z

    I expected to get output y = 6 and z = 10 but I get index out of bounds when I try to call x[3] and x[2] never seems to get set to the new value.

    Any help pointing me in the right direction would be much appreciated.

    Dave


  • 2.  RE: Stuck on lists

    Employee
    Posted 10-10-2013 13:03

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: johnpelz

    Hi Dave,

    Both the setItem and append functions will return a copy of the list with the updated values; however, you need to set that to "something" in order to preserve the changes. See below as an example to get the results you expected:

    x = list(1,2,3)
    x = setItem(x, 2, 6)
    x = x.append(10)

    y = x[2]
    z = x[3]
    emit y, z


  • 3.  RE: Stuck on lists

    Employee
    Posted 10-11-2013 00:15

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dstacey

    Thanks John - that's perfect!