Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3302 > unrolled thread
| Started by | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| First post | 2011-06-26 10:25 +0000 |
| Last post | 2011-06-26 10:25 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: How can I concatenate elements Bob Hanlon <hanlonr@cox.net> - 2011-06-26 10:25 +0000
| From | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| Date | 2011-06-26 10:25 +0000 |
| Subject | Re: How can I concatenate elements |
| Message-ID | <iu71el$189$1@smc.vnet.net> |
s1 = {1, 2, 3, 4, 5, 6};
s2 = {c, k};
s3 = Flatten@Outer[StringJoin[ToString /@ {#2, #1}] &, s2, s1]
{"1c", "2c", "3c", "4c", "5c", "6c", "1k", "2k", "3k", "4k", "5k", \
"6k"}
s4 = Flatten@
Table[StringJoin[ToString /@ {nbr, ltr}], {ltr, s2}, {nbr, s1}]
{"1c", "2c", "3c", "4c", "5c", "6c", "1k", "2k", "3k", "4k", "5k", \
"6k"}
s5 = Flatten@
Thread@Outer[StringJoin, Sequence @@ Map[ToString, {s1, s2}, {2}]]
{"1c", "2c", "3c", "4c", "5c", "6c", "1k", "2k", "3k", "4k", "5k", \
"6k"}
s3 === s4 === s5
True
Bob Hanlon
---- Leandro Tenfen <leandrotenfen@hotmail.com> wrote:
=============
Hi,
I have two lists:
s1={1,2,3,4,5,6};
s2={c,k};
How can I concatenate elements of lists as follows:
s3={1c,2c,3c,4c,5c,6c,1k,2k,3k,4k,5k,6k}
Many Thanks!
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web