Answer the question
In order to leave comments, you need to log in
Python as it is
Suppose there is such a multidimensional array:
a= [1, 2 ,3 ,4]
[ 3, 4, 5, 6]
[5, 3, 2, 2]
. . .
there is a second array
b= [ 1:[ab, ba]]
[2:[bc, cd]]
We need to make sure that it checks the values of the first array and, if there is a match, appends it like this:
a=
Answer the question
In order to leave comments, you need to log in
a = [
[1, 2 ,3 ,4],
[3, 4, 5, 6],
[5, 3, 2, 2]
]
b = {
1: ['ab', 'ba'],
2: ['bc', 'cd']
}
for r, row in enumerate(a):
a[r] = map(lambda x: [x]+b[x] if x in b else x, row)
print a
a=
b= { 1:['ab', 'ba'],
2: ['bc', 'cd']}
for k,mas in enumerate(a):
....for i,j in enumerate(mas):
........c = b.get(j)
............if len(q)<=k or len(q)==0:
................q.append([ ])
............if c:
................q[k].append([j,c[0],c[ 1]])
............else:
................q[k].append(j) Replace
dots with spaces/tabs as you feel more comfortable
Here is a quick solution for you =) The answer is:
[]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question