using every other character in a variable

I am trying to grab every other character in a very long variable, and placing it in another variable. This is what I have:

set_fact:

new_string: “{{ [ 0,2,4,6,8,10,12 ] | map(‘extract’, verylongvariable) }}”

I’ve also tried this:
set_fact:
new_string: "{{ [ 0,2,4,6,8,10,12 ] | map(‘extract’, verylongvariable) }} | map(‘join’, ‘,’ | join(‘’)) }}

What I end up getting in the new_string is this:

‘N’, ‘y’, ‘a’, ‘d’…

What I want is:

Nyad…

I clearly am not understanding the join syntax. How do I use join to get the new variable?

All you need is to use is slicing with a step:

If my variable is verylongvariable: s1i2v3e4l5

If I want sivel, I’d use: {{verylongvariable[::2]}}

If I want 12345, I’d use: {{verylongvariable[1::2]}}

Great thank you! Is there documentation somewhere on using ‘::’ ? I’ve looked everywhere…

You just need a join to make your current expression's output (list)
into a string.
But @sivel's solution with slicing is probably better, the reason you
cannot find it in documentation is because this is a "Pythonism" and a
property of Python list objects.
Ansible uses Jinja for expression evaluation, Jinja compiles into
Python in the end and exposes many of the properties of those Python
objects, neither Ansible nor Jinja document these properties so you
would need to a) know the type of object you are dealing with and b)
look at python documentation for those objects.

You can find the information about slicing within the python docs at: https://docs.python.org/3/library/functions.html#slice

Probably some other docs spread around as well that go into more depth.

What are some good resources to learn Ansible "pythonism" filters? I struggle with string manipulation, sets, dict merging, etc. In my opinion this is one of the greatest strengths of Ansible.

How did you guys learn it? Did you learn it because you knew python first?

Regards,
Stan