Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python

Name: Anonymous 2010-10-28 16:16

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

Name: Anonymous 2010-10-28 16:27


double xs []     = xs
double xs (y:ys) = double ys $ (take y xs) ++ (xs !! y * 2) ++ (drop (y + 1) xs)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List