Message Boards Message Boards

0
|
3797 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Create following list?

Posted 5 years ago

Hi, there are two list fs, fi;:

fs = Range[6];
fi = {"a", "b", "c", "d", "u", "y"};

I would like to create following list more efficiently not input again:

{1 -> "a", 2 -> "b", 3 -> "c", 4 -> "d", 5 -> "u", 6 -> "y"}

How to do

POSTED BY: Licheng Zhang
2 Replies

Try:

MapIndexed[First[#2] -> #1 &, fi]

or:

Thread[fs -> fi]
POSTED BY: Henrik Schachner
Posted 5 years ago

thank you! it is cute code

POSTED BY: Licheng Zhang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract