Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This is my first time asking a question on this forum.

I would like to generate a list with a range of numbers and use this list for a function to read from. Ok, now for the good part, it would look like this when done.

In[1]:= Range[5,10]

gives me

Out[1]:= {5 , 6, 7, 8, 9, 10}

What I want is {5->, 6->, 7->, 8->, 9->, 10->}, the range of numbers with the Rule infix operator after each element!

share|improve this question
1  
Could you say how/where you'd use the output you're after ? –  b.gatessucks Feb 1 '13 at 23:20
    
Trying to use that list to iterate through a function. –  Bob Brooks Feb 1 '13 at 23:24
2  
Could you make a small, concrete example ? –  b.gatessucks Feb 1 '13 at 23:26
1  
@Nasser Sequence @@@ {} doesn't do anything as there is no level one. Also, Rule has SequenceHold so you can do # -> Sequence[] & /@ Range[5, 10] if that's what you're after. Bob, it's not at all clear what you are really trying to do. If you are trying to delete elements from a list the the line above will do it, inefficiently. Do you just want to print some strings of the form 5 ->? –  Mr.Wizard Feb 2 '13 at 0:10
    
Just logged on and man…. I’ve got a lot to learn about Mathematica. I was trying to make a matrix of 0’s and 1’s to show a timeline of amounts of labor demand through time that corresponds to added load throughout a 24 hour period. The list I was trying to build was fundamentally flawed, due to my underdeveloped skill of WM. –  Bob Brooks Feb 2 '13 at 3:25
show 3 more comments

closed as not a real question by Ajasja, Mr.Wizard Feb 2 '13 at 12:09

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Here is what you can do. Store your list in some variable, say, lis1 = Range[5,10]. If you want to map those Rules to some other list, lis2 = {a, b, c, d, e, f}, containing the data you want to apply the rules to. You can use MapThread as follows: MapThread[Rule, {lis1, lis2}] This then gives {5 -> a, 6 -> b, 7 -> c, 8 -> d, 9 -> e, 10 -> f}

share|improve this answer
add comment

My interpretation of your question agrees with interpretation made by RunnyKine, but I'm guessing that you want a function that can create a list of rules, so the following generalization of RunnyKine's answer might be of interest.

makeRules[patterns_List, replacements_List] /; 
          Length[patterns] == Length[replacements] := 
  MapThread[Rule, {patterns, replacements}]

With this function you could create a variety of rules:

items = {a, b, c, d, e, f};

makeRules[Range[5, 10], items]

{5 -> a, 6 -> b, 7 -> c, 8 -> d, 9 -> e, 10 -> f}

rules = List[#] & /@ makeRules[ConstantArray[x, 6] , items]

{{x -> a}, {x -> b}, {x -> c}, {x -> d}, {x -> e}, {x -> f}}

x^2 + x /. rules

{a + a^2, b + b^2, c + c^2, d + d^2, e + e^2, f + f^2}

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.