python - Iterating over an array and dictionary and storing the values in another array -


say have dictionary of pattern types:

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

and have array:

a = [[1,3,4,5],[6,7,8,9]] 

i have 2 empty arrays store value of each pattern type:

pattern1=[] pattern5=[] 

i iterating on each row in , each pattern type in patterndict:

for row in a:     key, value in patterndict.iteritems():         currentpattern = row[value] value in patterndict[key]         #append either pattern1 or pattern5 currentpattern based on key 

and having trouble. how append either pattern 1 array or pattern 5 array based on key in patterndict. output like:

pattern1=[1,6] pattern5=[1,5,6,9] 

what's best way this?

use dict instead of variables:

>>> p = {k:[x[y] x in y in v] k, v in patterrndict.iteritems()} >>> p[1] [1, 6] >>> p[5] [1, 5, 6, 9] 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -