I am trying to write a program using a for or while loop that takes in two lists ([10,20,30,40] and [0,0,1,2]) for instance and the values of the second list are supposed to be the indexes of the first list that are supposed to be doubled
output: [40, 40, 60, 40]
the original string isn't supposed to be changed
does anyone have any suggestions? I've gotten:
def double(A,B):
i = 0
a = []
while i < len(B):
a = A[B[i]] * 2
i += 1
return A
Destructive version (add an &aux sequence (copy-seq sequence) to the lambda-list, if you want it to be non-distructive):
(defun double-sequence-by-indices (sequence indexes)
(dolist (index indexes sequence)
(symbol-macrolet ((element (elt sequence index)))
(incf element element))))
Example: CL-USER> (double-sequence-by-indices '(10 20 30 40) '(0 0 1 2))
(40 40 60 40)
Works on any kind of sequence (list, array or user-defined sequences (only some implementations support those)).
>>11
Downvote for use of faggot characters. Fuck, I might as well just write an OCR to approximate your faggot shit to proper ASCII that will render correctly in my /dev/tty0.
>>11
Downvote for use of faggot characters. Fuck, I might as well just write an OCR to approximate your faggot shit to proper ASCII that will render correctly in my /dev/tty0.