I have this array which has 4 element each. And I want to replace the same element before with empty string.
arr1 = [
["Ford", "Fiesta", "Manual", "$ 120,000,000"],
["Ford", "Fiesta", "Manual", "$ 134,000,000"],
["Ford", "Fiesta", "Automatic", "$ 140,000,000"],
["Ford", "Fiesta", "Automatic", "$ 150,000,000"],
["Ford", "Focus", "Manual", "$ 330,000,000"],
["Ford", "Focus", "Manual", "$ 335,000,000"],
["Ford", "Focus", "Manual", "$ 350,000,000"],
["Ford", "Focus", "Automatic", "$ 360,000,000"],
["VW", "Golf", "Manual", "$ 350,000,000"],
["VW", "Golf", "Automatic", "$ 370,000,000"]
];
So the result would be like :
[
["Ford", "Fiesta", "Manual", "$ 120,000,000"],
["", "", "", "$ 134,000,000"],
["", "", "Automatic", "$ 140,000,000"],
["", "", "", "$ 150,000,000"],
["", "Focus", "Manual", "$ 330,000,000"],
["", "", "", "$ 335,000,000"],
["", "", "", "$ 350,000,000"],
["", "", "Automatic", "$ 360,000,000"],
["VW", "Golf", "Manual", "$ 350,000,000"],
["", "", "Automatic", "$ 370,000,000"]
];
I have tried to create new array which include all the unique element, and loop it and then append it into 3rd array
arr2 = ["Ford", "Fiesta", "Focus", "Manual", "Automatic", "VW", "Golf"],
arr3 = []
print('-----------------------------------')
for x in arr1 :
print("X[0] ", x[0])
print("X[1] ", x[1])
print("X[2] ", x[2])
print("X[3] ", x[3])
if(x[0] == arr1[0][0]):
arr3.append("")
if(x[1] == arr1[0][1]):
arr3.append("")
if(x[2] == arr1[0][2]):
arr3.append("")
if(x[2] != arr1[0][2]):
arr3.append(x[2])
arr3.append(x[3])
But my result only correct for the 2nd row :
['', '', '', '$ 120,000,000',
'', '', '', '$ 134,000,000',
'', '', 'Automatic', '$ 140,000,000',
'', '', 'Automatic', '$ 150,000,000',
'', '$ 330,000,000', '', '$ 335,000,000',
'', '$ 350,000,000', '', '$ 360,000,000',
'$ 350,000,000', '$ 370,000,000']
Can someone tell me where my mistake please? Thanks in Advance