Adding data to list

hi,

Ex:

put (A,B,A,C,B) into Answers

(1) I want the items of list should be changed or replaced with letter like

(A,B,A,C,B) to (B,C,B,B,A) this should be new list of Answers

(2) I want to append another letter like

(A,B,A,C,B) to (AB,BA,ABC,AB) this should be new list of Answers

one more can it be possible to change only first 2 list items or first 2 items to increase one letter and another 3 should decrease one lette

please please reply

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    Unless there's something more to the problem, in your first example you'd just set the variable to the new list:
    put (A,B,A,C,B) into Answers
    //do stuff
    put (B,C,B,B,A) into Answers
    //do other stuff
    
    I don't really understand your second example. Where are the letters coming from that you want to append to the existing list? Are you trying to meld two lists together? There's no pattern or logic to what what you have there. The best I can suggest is to do something like this:
    put (A,B,A,C,B) into Answers
    repeat with each item of (B,C,B,B,A)
    	put it after item repeatIndex() of Answers
    end repeat
    put Answers -- outputs (AB,BC,AB,CB,BA)
    
    one more can it be possible to change only first 2 list items or first 2 items to increase one letter and another 3 should decrease one lette
    There's no one line solution, and you don't say exactly what you're adding or subtracting. Is it a specific letter, or is it a seemingly random selection like the example above? That said you can write code like this:
    put (A,B,A,C,B) into Answers
    repeat with each item of (B,C,B,B,A)
    	put it after item repeatIndex() of Answers
    end repeat
    put (AB,BC,AB,CB,BA) into Answers 
    repeat with each item of items 1 to 2 of Answers by reference
    	put B after it
    end repeat
    put Answers -- outputs (ABC,BCC,AB,CB,BA)
    repeat with each item of the last 3 items of Answers by reference
    	delete "B" in it
    end repeat
    put Answers -- outputs (ABB,BCB,A,C,A)
    
Sign In or Register to comment.