# I want to list the 0th value of each element in a two-dimensional array

Asked 3 months ago, Updated 3 months ago, 6 views

This is Python.

`````` data=[
['8',  '6', '7'],
['5',  '0', '8'],
['2', '12', '4'],
['0',  '7', '9']
]

``````

In response to this data,

`````` ['8', '8', '12', '9']
``````

I would like to print this out, but I can't get the last element, and the previous element will be printed.

Below is the program.

``````defind_max(data, begin, end):
for a in data [begin-1]:
data1 = sorted (data[begin-1], reverse = True)

begin + = 1
result=data1
print(result)
return result
``````

python

2022-09-30 12:09

`````` data=[
['8',  '6', '7'],
['5',  '0', '8'],
['2', '12', '4'],
['0',  '7', '9']
]

print([max(r,key=int)for rindata])
``````

2022-09-30 12:09

I don't think the `begin` or `end` parameters are required for the intended action to be inferred from what is written in the question.

`begin` and `end` are remnants of the previous question, and are they not necessary for this question?
Two-dimensional array row/column extraction

"If you want to ""extract and list the maximum values for each row in the specified 2D array"" that is inferred from the question, you can do this."

`````` data=[
['8',  '6', '7'],
['5',  '0', '8'],
['2', '12', '4'],
['0',  '7', '9']
]

data = [str(max(map(int,row))))) for row in data ]
``````

If you compare the string (with 1 origin), the maximum value of the third line is `4`, so we convert it to `int` before processing it.

I didn't notice that python sometimes combines various functions.
max(iterable,*[,key,default])

2022-09-30 12:09

## If you have any answers or tips

Popular Tags
python x 4566
android x 1593
java x 1484
javascript x 1415
c x 916
c++ x 866
ruby-on-rails x 694
php x 688
python3 x 675
html x 650