How to iterate over Vector{String} elements and append a string to them

Hi,
I have the Vector{String}, e.g.,

vec = ["P1", "P2", ..., "Pn", "SC", "TC"]

and I would like therefrom to create the corresponding modified Vector{String}:

vec_mod = ["P1_O", "P1_D", "P2_O", "P2_D", ..., "Pn_O", "SC_O", "SC_D", "TC_O", "TC_D"]

How do I implement this generically?
Thanks in advance.

Here I’m assuming you meant that the last entry in the “P” series was “Pn_D” instead of “Pn_O”. Then how about

julia> vec = ["P1", "P2", "P3", "P4", "SC", "TC"]
6-element Vector{String}:
 "P1"
 "P2"
 "P3"
 "P4"
 "SC"
 "TC"

julia> vec_mod = [x * suffix for x in vec for suffix in ["_O", "_D"]]
12-element Vector{String}:
 "P1_O"
 "P1_D"
 "P2_O"
 "P2_D"
 "P3_O"
 "P3_D"
 "P4_O"
 "P4_D"
 "SC_O"
 "SC_D"
 "TC_O"
 "TC_D"
3 Likes

That’s what I really meant in my OP. So simple (the power of comprehensions)! Thanks, @hendri54

FWIW, multiplication could be broadcasted to achieve the same result:

v = ["P1", "P2", "Pn", "SC", "TC"]
s = ["_O"  "_D"]
vec(permutedims(v .* s))
1 Like

@rafael.guerra:Thanks for the further enlightenment. However, I have to confess I find @hendri54’s accepted solution more understandable…