I have data in the list namely, row and I have a list of indexes namely, indexes
How to print that data based on index.
For ex.
rows = [['1', 'John', '20'],
['2', 'Mary', '19'],
['3', 'Alex', '20'],
['4', 'Jaydeep', '24'],
['5', 'Meet', '23'],
['6', 'Parth', '25']
]
and
indexes = [0,1]
Then I want to print
for row in rows:
print(row[0], row[1])
CodePudding user response:
something like the below (as far as I understand the question..)
row = [7,12,90]
indexs = [2,0,1]
for i in indexs:
print(row[i])
output
90
7
12
CodePudding user response:
The question is confusing. if you are looking for the array value, use balderman's answer. from your question, it is understandable that you need to display "print". in that case use below code.
row=[1,2,3,4]
indexes=[0,1,2,3]
res="print "
for i in indexes:
res =" row[{0}],".format(i)
print(res)