1

If I have an array:

 A = [1,3,4,5]

And a dictionary that corresponds with pattern types, such that pattern type 0 was position 0 of the array, and pattern type 5 was index 0, index 3 of the array:

 patterrnDict = {1:[0],5:[0,3]}

Now say for pattern type 5, I only care about the value, so while patternDict[5] would return 1,5, I really want the value of 1+5, so I want an output of 6. How would I achieve this?

2
  • 2
    I'm afraid I'm having difficulty understanding what you are asking. Commented Sep 24, 2013 at 5:17
  • 1
    sum(A[i] for i in patterrnDict[5]) Commented Sep 24, 2013 at 5:20

2 Answers 2

4

Something like this:

>>> sum(A[index] for index in patternDict[5])
Sign up to request clarification or add additional context in comments.

Comments

-1
reduce(lambda x,y:x+y, map(A.__getitem__, pd[5]))

certainly, you can write a function to do this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.