Skip to main content
Solved

How to append a value to a list?

  • February 13, 2017
  • 6 replies
  • 468 views

Forum|alt.badge.img+1

Hi!

I have a list, containing between 5 and 50 values (varying). How can I append a value to this list? I can only assume there has to be a non-pythonic way, but I struggle to find one. My approach was to use AttributeCreator, but I can't dynamically specify the position in the list. Had the list size been fixed, then that's a solution - but not in this case.

Any ideas?

Best answer by david_r

You can use the ListElementCounter to find the last position, which you can then use in the AttributeCreator. Example, assuming your list is called "list{}":

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

david_r
Celebrity
  • Best Answer
  • February 13, 2017

You can use the ListElementCounter to find the last position, which you can then use in the AttributeCreator. Example, assuming your list is called "list{}":


Forum|alt.badge.img+1
  • Author
  • February 14, 2017

You can use the ListElementCounter to find the last position, which you can then use in the AttributeCreator. Example, assuming your list is called "list{}":

Of course! I didn't see it in the popup specifying "input a number" and didn't think of this manual way to do it. Good call - this should work.

 

 

However, I can't get it to "evaluate" properly? Instead, it creates an attribute called list{@Value(_element_count)}

 

 


david_r
Celebrity
  • February 14, 2017
Of course! I didn't see it in the popup specifying "input a number" and didn't think of this manual way to do it. Good call - this should work.

 

 

However, I can't get it to "evaluate" properly? Instead, it creates an attribute called list{@Value(_element_count)}

 

 

Which version of FME are you using? I tested with FME 2016.1.3.1.

 

 


Forum|alt.badge.img+1
  • Author
  • February 14, 2017
Which version of FME are you using? I tested with FME 2016.1.3.1.

 

 

Okay, now it works here too. However, it also exposes an attribute called list{@Value(count)}, which confused me. Thanks, David!

takashi
Celebrity
  • February 14, 2017
Which version of FME are you using? I tested with FME 2016.1.3.1.

 

 

Yes, the exposed list{@Value(count)} annoys us a bit.

 

For what it's worth, if you want to avoid to expose it, and also do not use Python, Tcl scripting would be an alternative. Assuming an attribute called "_newValue" stores the new value to be appended to the "_list{}".

 

Tcl Expression for a TclCaller

 

FME_SetAttribute _list{[FME_Execute NumElements _list{}]} [FME_GetAttribute _newValue]
FME Function call in an FMEFunctionCaller

 

@Tcl2("FME_SetAttribute _list{[FME_Execute NumElements _list{}]} @Value(_newValue)")
YES, I know you don't like to use Tcl, @david_r ;-)

syedh2993
Contributor
Forum|alt.badge.img+7
  • Contributor
  • December 31, 2024

Hi All,

I am working with lists and require some guidance on the below scenario

I have list which contains 'n' elements. I would like to add a sub-element to each element in the list.

Assuming my list name called as "list{}"

Example: (My list currently looks like this)

    List{0}
        element1
        element2
        element3
    List{1}
        element1
        element2
        element3
    List{2}
        element1
        element2
        element3
    List{n}
        element1
        element2
        element3

        
I would like to add new sub-element called "element4" at the end of each list element (i.e., add "element4" as sub-element below "element3" )        

Expected Output (I would like to achieve something like below)

    List{0}
        element1
        element2
        element3
        element4
    List{1}
        element1
        element2
        element3
        element4
    List{2}
        element1
        element2
        element3
        element4
    List{n}
        element1
        element2
        element3
        element4


Would really appreciate your help in achieving the above expected output.

Thanks